class haxe.macro.ExprTools
Available on all platforms
This class provides some utility methods to work with expressions. It is best used through 'using haxe.macro.ExprTools' syntax and then provides additional methods on haxe.macro.Expr instances.
While mainly intended to be used in macros, it works in non-macro code as well.
Class Fields
static function iter(e:Expr, f:Expr ->Void):Void
Calls function [f] on each sub-expression of [e].
If [e] has no sub-expressions, this operation has no effect.
Otherwise [f] is called once per sub-expression of [e], with the sub-expression as argument. These calls are done in order of the sub-expression declarations.
This method does not call itself recursively. It should instead be used in a recursive function which handles the expression nodes of interest.
Usage example:
function findStrings(e:Expr) {
switch(e.expr) {
case EConst(CString(s)):
// handle s
case _:
ExprTools.iter(e, findStrings);
}
}
static function map(e:Expr, f:Expr ->Expr):Expr
Transforms the sub-expressions of [e] by calling [f] on each of them.
If [e] has no sub-expressions, this operation returns [e] unchanged.
Otherwise [f] is called once per sub-expression of [e], with the sub-expression as argument. These calls are done in order of the sub-expression declarations.
This method does not call itself recursively. It should instead be used in a recursive function which handles the expression nodes of interest.
Usage example:
function capitalizeStrings(e:Expr) {
return switch(e.expr) {
case EConst(CString(s)):
{ expr: EConst(CString(s.toUpperCase())), pos: e.pos };
case _:
ExprTools.map(e, capitalizeStrings);
}
}