Method
expandMacro(_:arguments:bodyContent:)
Expands a macro invocation with the specified arguments.
@MainActor func expandMacro(_ macro: MTLMacro, arguments: [(any EcoreValue)?], bodyContent: MTLBlock? = nil) async throws
Parameters
macro-
The macro to expand
arguments-
The arguments matching the macro parameters
bodyContent-
The captured body content (if macro has body parameter)
Discussion
Macros are language extension mechanisms that accept both regular parameters and captured body content.
Example
let macro = MTLMacro(
name: "repeat",
parameters: [MTLVariable(name: "count", type: "Integer")],
bodyParameter: "content",
body: MTLBlock(statements: [
MTLForStatement(
binding: MTLBinding(...),
body: MTLBlock(statements: [
// Execute captured content here
])
)
])
)
try await generator.expandMacro(
macro,
arguments: [3],
bodyContent: MTLBlock(statements: [
MTLTextStatement(value: "Repeated line")
])
)