HaxeDoc2

(やまだぃちぅ) #1

Chapter 9


9 Macros


Macros are without a doubt the most advanced feature in Haxe. They are often perceived as dark
magic that only a select few are capable of mastering, yet there is nothing magical (and certainly
nothing dark) about them.


Definition: Abstract Syntax Tree (AST)
The AST is the result ofparsingHaxe code into a typed structure. This structure is exposed
to macros through the types defined in the filehaxe/macro/Expr.hxof the Haxe Standard
Library.

Source code Lexer / Parser Abstract Syntax Tree (AST)


  • Expression

  • Complex Type

  • haxe.macro.Expr


Macro processor

Typed AST Typer Abstract Syntax Tree (AST)


  • Typed Expression

  • Type

  • haxe.macro.Type


Generator

Output

parse

transform

type

generate

Figure 9.1: The role of macros during compilation.

A basic macro is asyntax-transformation. It receives zero or more expressions ( 5 ) and also
Free download pdf