Structure
MTLModule
Represents an MTL (Model-to-Text Language) module.
struct MTLModule
Overview
An MTL module is the root container for a text generation specification, containing source metamodels, templates, queries, macros, and module-level configuration. MTL modules define transformations from models to text using declarative templates and imperative control structures.
Overview
MTL modules follow a structured approach to model-to-text transformation:
-
Metamodels: Reference metamodels that define the structure of input models
-
Templates: Text generation units with parameters and control flow
-
Queries: Side-effect-free operations for computed values
-
Macros: Language extensions for pattern reuse
-
Module hierarchy: Inheritance and imports for modular organization
Module Inheritance
MTL supports module inheritance through the extends mechanism, allowing templates to be specialized and overridden in module hierarchies:
// Base module
let baseModule = MTLModule(
name: "BaseGen",
metamodels: ["Model": modelPackage],
templates: ["generate": baseTemplate]
)
// Derived module (overrides base template)
let derivedModule = MTLModule(
name: "DerivedGen",
metamodels: ["Model": modelPackage],
extends: "BaseGen",
templates: ["generate": overridingTemplate]
)
Example Usage
let module = MTLModule(
name: "ClassGenerator",
metamodels: ["UML": umlPackage],
templates: ["generateClass": classTemplate],
queries: ["isPublic": isPublicQuery],
macros: ["repeat": repeatMacro],
encoding: "UTF-8"
)
Topics
Operators
Compares two MTL modules for equality.
Initializers
Creates a new MTL module with the specified configuration.
Instance Properties
The default character encoding for generated files.
Optional parent module name for inheritance.
Imported module names for namespace composition.
Macros indexed by their names.
Source metamodels indexed by their namespace aliases.
The name of the MTL module.
Queries indexed by their names.
Templates indexed by their names.
Instance Methods
Hashes the essential components of the module into the given hasher.
Default Implementations
Relationships
Conforms To
See Also
Module Structure
Represents an MTL template for text generation.
Represents an MTL query - a side-effect-free operation returning a value.