helper for clean expression building
This commit is contained in:
@@ -328,4 +328,20 @@ class Helpers {
|
||||
};
|
||||
return def.withPosOf(exp);
|
||||
}
|
||||
|
||||
// Return convenient functions for succinctly making new ReaderExps that link back to an original exp's
|
||||
// position in source code
|
||||
public static function expBuilder(posRef:ReaderExp) {
|
||||
return {
|
||||
call: (func:ReaderExp, args:Array<ReaderExp>) -> CallExp(func, args).withPosOf(posRef),
|
||||
list: (exps:Array<ReaderExp>) -> ListExp(exps).withPosOf(posRef),
|
||||
str: (s:String) -> StrExp(s).withPosOf(posRef),
|
||||
symbol: (name:String) -> Symbol(name).withPosOf(posRef),
|
||||
raw: (code:String) -> RawHaxe(code).withPosOf(posRef),
|
||||
typed: (path:String, exp:ReaderExp) -> TypedExp(path, exp).withPosOf(posRef),
|
||||
meta: (m:String, exp:ReaderExp) -> MetaExp(m, exp).withPosOf(posRef),
|
||||
field: (f:String, exp:ReaderExp) -> FieldExp(f, exp).withPosOf(posRef),
|
||||
keyValue: (key:ReaderExp, value:ReaderExp) -> KeyValueExp(key, value).withPosOf(posRef),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@@ -22,7 +22,14 @@ class Macros {
|
||||
function destructiveVersion(op:String, assignOp:String) {
|
||||
macros[assignOp] = (wholeExp:ReaderExp, exps:Array<ReaderExp>, k) -> {
|
||||
wholeExp.checkNumArgs(2, null, '($assignOp [var] [v1] [values...])');
|
||||
CallExp(Symbol("set").withPosOf(wholeExp), [exps[0], CallExp(Symbol(op).withPosOf(wholeExp), exps).withPosOf(wholeExp)]).withPosOf(wholeExp);
|
||||
var b = wholeExp.expBuilder();
|
||||
b.call(
|
||||
b.symbol("set"), [
|
||||
exps[0],
|
||||
b.call(
|
||||
b.symbol(op),
|
||||
exps)
|
||||
]);
|
||||
};
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user