Documentation Language: Swift

Framework

MTL

A pure Swift implementation of the https://www.omg.org/spec/MOFM2T/ standard for template-based code generation.

Overview

MTL provides a template-based approach to code generation from models. Define templates with embedded queries that navigate your model, and MTL generates output files with the evaluated content.

This implementation follows the https://www.omg.org/spec/MOFM2T/ and is compatible with https://eclipse.dev/acceleo/, whilst providing a modern Swift API for integration with the ECore metamodelling framework.

Key Features

Quick Example

import MTL
import ECore

// Parse the template module
let parser = MTLParser()
let module = try await parser.parse(URL(fileURLWithPath: "SwiftGenerator.mtl"))

// Configure output
let strategy = MTLFileGenerationStrategy(
    outputDirectory: URL(fileURLWithPath: "./Sources/Generated")
)

// Create context and register model
let context = MTLExecutionContext(module: module, generationStrategy: strategy)
try await context.registerModel(modelResource, as: "model")

// Execute
let executor = MTLExecutor(context: context)
try await executor.execute()

Topics

Essentials

A
Getting Started with MTL

Learn how to add MTL to your project and create your first code generator.

A
Understanding MTL

Learn the fundamental concepts of the Model-to-Text Language.

Execution

C
MTLExecutionContext

Manages the execution state for MTL template generation.

P
MTLGenerationStrategy

Protocol for MTL text generation output strategies.

Module Structure

S
MTLModule

Represents an MTL (Model-to-Text Language) module.

S
MTLTemplate

Represents an MTL template for text generation.

S
MTLQuery

Represents an MTL query - a side-effect-free operation returning a value.

Template Elements

S
MTLBlock

Represents a block of MTL statements.

Protected Regions

?
MTLProtectedAreaManager

Thread-safe manager for preserving protected area content across regenerations.

Parsing

?
MTLParser

Parser for MTL (Model-to-Text Language) templates.

Errors

E
MTLExecutionError

Errors that can occur during MTL template execution.

E
MTLParseError

Errors that can occur during MTL parsing and serialization.

Classes

?
MTLFileSystemStrategy

File system-based generation strategy that writes to disk.

C
MTLGenerator

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

?
MTLInMemoryStrategy

In-memory generation strategy for testing and programmatic access.

?
MTLWriter

Thread-safe actor for accumulating generated text with automatic indentation.

Protocols

P
MTLStatement

Protocol for all MTL statements that can be executed within templates.

Structures

S
MTLBinding

Represents a variable binding with an initialization expression.

S
MTLComment

A statement representing a comment that produces no output.

S
MTLExpression

A thin wrapper around AQL expressions for MTL template evaluation.

S
MTLExpressionStatement

A statement that evaluates an expression and outputs the result.

S
MTLFileStatement

A file statement for directing output to a file.

S
MTLForStatement

A for loop statement for iterating over collections.

S
MTLGenerationStatistics

Statistics about MTL template execution.

S
MTLIfStatement

A conditional statement for branching logic.

S
MTLIndentation

Manages indentation levels and whitespace generation for MTL text output.

S
MTLLetStatement

A let statement for variable binding in a nested scope.

S
MTLMacro

Represents an MTL macro for language extension.

S
MTLMacroInvocation

A macro invocation statement.

S
MTLNewLineStatement

A statement that outputs a newline with optional indentation.

S
MTLProtectedArea

A protected area statement for preserving user code across generations.

S
MTLTextStatement

A statement that outputs literal text to the current writer.

S
MTLTrace

A trace statement for recording traceability links.

S
MTLTraceLink

Represents a trace link for model-to-text traceability.

S
MTLVariable

Represents a variable or parameter declaration in MTL.

Enumerations

E
MTLOpenMode

File operations mode enumeration.

E
MTLResourceError

Errors that can occur during MTL resource operations.

E
MTLVisibility

Visibility levels for MTL templates and queries.

See Also

Related Documentation