Documentation Language: Swift

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:

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

Instance Properties

V
body

The template body containing generation statements.

V
documentation

Optional documentation string.

V
guard

Optional guard condition for conditional execution.

V
isMain

Whether this template is a main entry point.

V
name

The name of the template.

V
overrides

Optional name of the template being overridden.

V
parameters

The parameters accepted by this template.

V
post

Optional post-condition for result validation.

V
visibility

The visibility of this template.

Default Implementations

Relationships

Conforms To

See Also

Module Structure

S
MTLModule

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

S
MTLQuery

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