Macro pragmas
All macros and templates can also be used as pragmas. They can be attached to routines (procs, iterators, etc), type names or type expressions. The compiler will perform the following simple syntactic transformations:
template command(name: string, def: untyped) = discard
proc p() {.command("print").} = discard
This is translated to:
command("print"):
proc p() = discard
type
AsyncEventHandler = proc (x: Event) {.async.}
This is translated to:
type
AsyncEventHandler = async(proc (x: Event))
type
MyObject {.schema: "schema.protobuf".} = object
This is translated to a call to the schema macro with a nnkTypeDef AST node capturing both the left-hand side and right-hand side of the definition. The macro can return a potentially modified nnkTypeDef tree which will replace the original row in the type section.
When multiple macro pragmas are applied to the same definition, the compiler will apply them consequently from left to right. Each macro will receive as input the output of the previous one.