Documentation
¶
Overview ¶
Package macros extends the compiler with a @macro engine.
A @macro directive stores a declaration; OnPreprocess turns each declaration into a PrimaryExtension dispatching on TokAtPrompt; and every expansion re-enters the parser with the caller's arguments substituted into the body.
Typical use:
@macro greet(name) { const @{ value: $name } }
@greet("World") // expands to: const @{ value: "World" }
Without this bundle, @name is "unexpected token @name".
Index ¶
Constants ¶
const DeclarationKey = "macros"
DeclarationKey is the meta slot where @macro declarations land before OnPreprocess converts them to a PrimaryExtension.
const ID = "macros"
Variables ¶
var Directive = core.Directive{
Name: "macro",
Example: "@macro greet(name) {\n const @{ value: $name }\n}",
Handler: handleDirective,
}
Directive parses `@macro name(p1, p2) { body }` into a Declaration appended to meta[DeclarationKey]. Duplicate names are a compile error, not a silent override.
Functions ¶
Types ¶
type Declaration ¶
Declaration is the parsed form of `@macro name(params) { body }`.