diff --git a/src/tink/macro/Exprs.hx b/src/tink/macro/Exprs.hx index 7f68fe2..410b107 100644 --- a/src/tink/macro/Exprs.hx +++ b/src/tink/macro/Exprs.hx @@ -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"; diff --git a/tests/Exprs.hx b/tests/Exprs.hx index 5fd2bf0..bb4a5f7 100644 --- a/tests/Exprs.hx +++ b/tests/Exprs.hx @@ -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;})); + } } \ No newline at end of file