Macro pragmas

Macros and templates can sometimes be called with the pragma syntax. Cases where this is possible include when attached to routine (procs, iterators, etc.) declarations or routine type expressions. The compiler will perform the following simple syntactic transformations:

  1. template command(name: string, def: untyped) = discard
  2. proc p() {.command("print").} = discard

This is translated to:

  1. command("print"):
  2. proc p() = discard

  1. type
  2. AsyncEventHandler = proc (x: Event) {.async.}

This is translated to:

  1. type
  2. AsyncEventHandler = async(proc (x: Event))

When multiple macro pragmas are applied to the same definition, the first one from left to right will be evaluated. This macro can then choose to keep the remaining macro pragmas in its output, and those will be evaluated in the same way.

There are a few more applications of macro pragmas, such as in type, variable and constant declarations, but this behavior is considered to be experimental and is documented in the experimental manual instead.