haXe API Documentation
Back | Index
class haxe.macro.ExprTools
Available in flash8, neko, js, flash, php, cpp

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.

static function asIdent(s : String, p : Position) : Expr
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
static function toFieldExpr(sl : Array<String>) : Expr
static function toString(e : Expr) : String

Converts expression e to a human-readable String representation.

The result is guaranteed to be valid haxe code, but there may be differences from the original lexical syntax.

Back | Index