Documentation Language: Swift

Class

MTLGenerator

Main execution engine for MTL model-to-text transformations.

@MainActor final class MTLGenerator

Overview

The MTL generator orchestrates the execution of MTL templates, managing the execution context, template invocation, query evaluation, and generation statistics. It coordinates all aspects of text generation from model inputs.

Overview

The generator provides:

Basic Usage

// Create module with templates
let module = MTLModule(
    name: "MyGenerator",
    metamodels: [:],
    templates: [
        "main": MTLTemplate(
            name: "main",
            parameters: [MTLVariable(name: "model", type: "Model")],
            body: ...,
            isMain: true
        )
    ]
)

// Create generator
let strategy = MTLInMemoryStrategy()
let generator = MTLGenerator(module: module, generationStrategy: strategy)

// Register models
var models: [String: Resource] = [:]
models["IN"] = inputModel

// Generate
try await generator.generate(
    mainTemplate: "main",
    arguments: [modelRoot],
    models: models
)

// Check results
print(generator.statistics.summary())

Template Execution

Templates are executed with parameter binding:

// Template with parameters
let template = MTLTemplate(
    name: "generateClass",
    parameters: [
        MTLVariable(name: "class", type: "Class"),
        MTLVariable(name: "package", type: "String")
    ],
    body: ...
)

// Execute with arguments
try await generator.executeTemplate(
    template,
    arguments: [classElement, "com.example"]
)

Statistics

The generator tracks detailed statistics:

print("Execution time: \(generator.statistics.executionTime)s")
print("Templates executed: \(generator.statistics.templatesExecuted)")
print("Files generated: \(generator.statistics.filesGenerated)")

Topics

Initializers

?
init(module:generationStrategy:)

Creates a new MTL generator for the specified module.

Instance Properties

V
module

The MTL module being executed.

V
statistics

Statistics about the current/last generation run.

Instance Methods

F
enableDebugging(_:)

Enables or disables debug mode.

F
executeQuery(_:arguments:)

Executes a query and returns its result.

F
executeTemplate(_:arguments:)

Executes a template with the specified arguments.

F
expandMacro(_:arguments:bodyContent:)

Expands a macro invocation with the specified arguments.

F
generate(mainTemplate:arguments:models:)

Executes the specified main template with the given arguments.

F
statisticsSummary()

Returns a detailed summary of the current statistics.

Relationships

Conforms To