Skip to content

Commit

Permalink
added macro $p{Array<String>} to generate an EField chain
Browse files Browse the repository at this point in the history
  • Loading branch information
Simn committed Jan 4, 2013
1 parent b6b8809 commit d1c1f9e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,8 @@ let reify in_macro =
(ECall ((EField ((EField ((EField ((EConst (Ident "haxe"),p),"macro"),p),"Context"),p),"makeExpr"),p),[e; to_pos (pos e)]),p)
| "$i" ->
(ECall ((EField ((EField ((EField ((EConst (Ident "haxe"),p),"macro"),p),"ExprTools"),p),"asIdent"),p),[e; to_pos (pos e)]),p)
| "$p" ->
(ECall ((EField ((EField ((EField ((EConst (Ident "haxe"),p),"macro"),p),"ExprTools"),p),"toFieldExpr"),p),[e]),p)
| _ ->
expr "EMeta" [to_obj [("name",to_string m p);("params",to_expr_array ml p);("pos",to_pos p)] p;loop e1]
in
Expand Down
6 changes: 5 additions & 1 deletion std/haxe/macro/ExprTools.hx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
package haxe.macro;

import haxe.macro.Expr;
using Lambda;

/**
This class provides some utility methods to work with expressions. It is
Expand All @@ -37,6 +38,9 @@ class ExprTools {
static public function asIdent( s : String, p:Position ) : Expr
return { expr : EConst(CIdent(s)), pos : p }

static public function toFieldExpr ( sl : Array<String> ) : Expr
return sl.fold(function(s, e) return e == null ? (macro $i{s}) : (macro $e.$s), null)

/**
Converts expression [e] to a human-readable String representation.
Expand Down Expand Up @@ -219,7 +223,7 @@ class ExprTools {
return e == null ? null : f(e)

static inline function opt2(e:Null<Expr>, f : Expr -> Void):Void
if (e != null) f(e)
if (e != null) f(e)
}

/**
Expand Down

0 comments on commit d1c1f9e

Please sign in to comment.