Structure
MTLTemplate
Represents an MTL template for text generation.
struct MTLTemplate
Overview
Templates are the primary text generation units in MTL, defining parameterized transformations from model elements to text. They can include guard conditions, post-conditions, and visibility controls for modular template libraries.
Overview
MTL templates provide:
-
Parameterization: Type-safe parameters for template invocation
-
Guards: Conditional execution based on runtime conditions
-
Post-conditions: Validation of template execution results
-
Visibility: Access control for template reuse
-
Overriding: Template specialization in module hierarchies
-
Main templates: Entry points for generation
Example Usage
// Simple template
let helloTemplate = MTLTemplate(
name: "sayHello",
parameters: [MTLVariable(name: "name", type: "String")],
body: MTLBlock(statements: [
MTLTextStatement(value: "Hello, "),
MTLExpressionStatement(expression: MTLExpression(AQLVariableExpression(name: "name"))),
MTLTextStatement(value: "!")
])
)
// Template with guard
let guardedTemplate = MTLTemplate(
name: "generateClass",
parameters: [MTLVariable(name: "class", type: "Class")],
guard: MTLExpression(AQLNavigationExpression(
source: AQLVariableExpression(name: "class"),
property: "isPublic"
)),
body: classBody
)
// Main template (entry point)
let mainTemplate = MTLTemplate(
name: "main",
parameters: [MTLVariable(name: "model", type: "Model")],
body: mainBody,
isMain: true
)
Topics
Initializers
Creates a new MTL template.
Instance Properties
The template body containing generation statements.
Optional documentation string.
Optional guard condition for conditional execution.
Whether this template is a main entry point.
The name of the template.
Optional name of the template being overridden.
The parameters accepted by this template.
Optional post-condition for result validation.
The visibility of this template.