Concat any exprs
This commit is contained in:
@@ -389,11 +389,15 @@ class Exprs {
|
||||
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
|
||||
switch [e.expr, with.expr] {
|
||||
case [EBlock(e1), EBlock(e2)]: Success(EBlock(e1.concat(e2)).at(pos == null ? e.pos : pos));
|
||||
default: e.pos.makeFailure(NOT_A_BLOCK);
|
||||
case [EBlock(e1), EBlock(e2)]: Success(EBlock(e1.concat(e2)).at(pos));
|
||||
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";
|
||||
|
||||
@@ -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