Concat any exprs
This commit is contained in:
@@ -389,12 +389,16 @@ class Exprs {
|
|||||||
default: e.pos.makeFailure(NOT_A_FUNCTION);
|
default: e.pos.makeFailure(NOT_A_FUNCTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
static public function concat(e:Expr, with:Expr, ?pos)
|
static public function concat(e:Expr, with:Expr, ?pos) {
|
||||||
|
if(pos == null) pos = e.pos;
|
||||||
return
|
return
|
||||||
switch [e.expr, with.expr] {
|
switch [e.expr, with.expr] {
|
||||||
case [EBlock(e1), EBlock(e2)]: Success(EBlock(e1.concat(e2)).at(pos == null ? e.pos : pos));
|
case [EBlock(e1), EBlock(e2)]: Success(EBlock(e1.concat(e2)).at(pos));
|
||||||
default: e.pos.makeFailure(NOT_A_BLOCK);
|
case [EBlock(e1), e2]: Success(EBlock(e1.concat([with])).at(pos));
|
||||||
|
case [e1, EBlock(e2)]: Success(EBlock([e].concat(e2)).at(pos));
|
||||||
|
default: Success(EBlock([e, with]).at(pos));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static inline var NOT_AN_INT = "integer constant expected";
|
static inline var NOT_AN_INT = "integer constant expected";
|
||||||
static inline var NOT_AN_IDENT = "identifier expected";
|
static inline var NOT_AN_IDENT = "identifier expected";
|
||||||
|
|||||||
@@ -80,4 +80,11 @@ class Exprs extends Base {
|
|||||||
])
|
])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testConcat() {
|
||||||
|
exprEq(macro {a; b;}, (macro a).concat(macro b).sure());
|
||||||
|
exprEq(macro {a; b; c;}, (macro {a; b;}).concat(macro c).sure());
|
||||||
|
exprEq(macro {a; b; c;}, (macro a).concat(macro {b; c;}).sure());
|
||||||
|
exprEq(macro {a; b; c; d;}, (macro {a; b;}).concat(macro {c; d;}).sure());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user