${}and$e{}: Expr -> ExprThis can be used to compose expressions. The expression within
the delimiting{}is executed, with its value being used in place.
$a{}: Expr -> Array
arguments, block elements),$a{}treats its value as that array. Otherwise it generates an
array declaration.
$b{}: Array
$i{}: String -> ExprGenerates an identifier from the given string.
$p{}: Array
$v{}: Dynamic -> ExprGenerates an expression depending on the type of its argument. This
is only guaranteed to work for basic types (2.1) and enum instances (2.4).
This kind of reification only works in places where the internal structure expects an expres-
sion. This disallowsobject.${fieldName}, butobject.$fieldNameworks. This is true for
all places where the internal structure expects a string:
- field accessobject.$name
- variable namevar $name = 1;
Since Haxe 3.1.0
- field name{ $name: 1}
- function namefunction $name() {}
- catch variable nametry e() catch($name:Dynamic) {}
9.3.2 Type Reification...................................
Type reification is used to create instances ofhaxe.macro.Expr.ComplexTypein a conve-
nient way. It is identified by amacro : Type, whereTypecan be any valid type path expres-
sion. This is similar to explicit type hints in normal code, e.g. for variables in the form ofvar
x:Type.
Each constructor ofComplexTypehas a distinct syntax:
TPath: macro : pack.Type
TFunction:macro : Arg1 -> Arg2 -> Return
TAnonymous:macro : { field: Type }
TParent: macro : (Type)
TExtend: macro : {> Type, field: Type }
TOptional:macro : ?Type