Merge pull request #8 from kevinresol/concat_block

Add concat()
This commit is contained in:
Juraj Kirchheim
2016-12-07 06:42:24 +01:00
committed by GitHub
2 changed files with 18 additions and 0 deletions

View File

@@ -388,6 +388,17 @@ class Exprs {
case EFunction(_, f): Success(f);
default: e.pos.makeFailure(NOT_A_FUNCTION);
}
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)]: EBlock(e1.concat(e2)).at(pos);
case [EBlock(e1), e2]: EBlock(e1.concat([with])).at(pos);
case [e1, EBlock(e2)]: EBlock([e].concat(e2)).at(pos);
default: EBlock([e, with]).at(pos);
}
}
static inline var NOT_AN_INT = "integer constant expected";
static inline var NOT_AN_IDENT = "identifier expected";

View File

@@ -80,4 +80,11 @@ class Exprs extends Base {
])
);
}
function testConcat() {
exprEq(macro {a; b;}, (macro a).concat(macro b));
exprEq(macro {a; b; c;}, (macro {a; b;}).concat(macro c));
exprEq(macro {a; b; c;}, (macro a).concat(macro {b; c;}));
exprEq(macro {a; b; c; d;}, (macro {a; b;}).concat(macro {c; d;}));
}
}