Merge branch 'master' of https://github.com/haxetink/tink_macro
This commit is contained in:
58
README.md
58
README.md
@@ -13,34 +13,34 @@ As Haxe evolved and some of the functionality has been integrated/reimplemented/
|
||||
|
||||
The library is build on top of the haxe macro API and `tink_core`, having three major parts:
|
||||
|
||||
<!-- START INDEX -->
|
||||
- [Macro API](#macro-api)
|
||||
-
|
||||
- [Expression Tools](#expression-tools)
|
||||
- [Basic Helpers](#basic-helpers)
|
||||
- [Extracting Constants](#extracting-constants)
|
||||
- [Shortcuts](#shortcuts)
|
||||
- [Type Inspection](#type-inspection)
|
||||
- [Advanced Transformations](#advanced-transformations)
|
||||
- [Position Tools](#position-tools)
|
||||
- [Type Tools](#type-tools)
|
||||
- [Function Tools](#function-tools)
|
||||
- [Operation Tools](#operation-tools)
|
||||
- [Metadata Tools](#metadata-tools)
|
||||
- [Build Infrastructure](#build-infrastructure)
|
||||
- [Member](#member)
|
||||
- [ClassBuilder](#classbuilder)
|
||||
- [Constructor](#constructor)
|
||||
- [Creation](#creation)
|
||||
- [Visibility](#visibility)
|
||||
- [Initial Super Call](#initial-super-call)
|
||||
- [Simple Modifications](#simple-modifications)
|
||||
- [Field Initialization](#field-initialization)
|
||||
- [Setter Bypass](#setter-bypass)
|
||||
- [Initialization Options](#initialization-options)
|
||||
- [Expression Level Transformation](#expression-level-transformation)
|
||||
- [TypeMap](#typemap)
|
||||
|
||||
<!-- START INDEX -->
|
||||
- [Macro API](#macro-api)
|
||||
-
|
||||
- [Expression Tools](#expression-tools)
|
||||
- [Basic Helpers](#basic-helpers)
|
||||
- [Extracting Constants](#extracting-constants)
|
||||
- [Shortcuts](#shortcuts)
|
||||
- [Type Inspection](#type-inspection)
|
||||
- [Advanced Transformations](#advanced-transformations)
|
||||
- [Position Tools](#position-tools)
|
||||
- [Type Tools](#type-tools)
|
||||
- [Function Tools](#function-tools)
|
||||
- [Operation Tools](#operation-tools)
|
||||
- [Metadata Tools](#metadata-tools)
|
||||
- [Build Infrastructure](#build-infrastructure)
|
||||
- [Member](#member)
|
||||
- [ClassBuilder](#classbuilder)
|
||||
- [Constructor](#constructor)
|
||||
- [Creation](#creation)
|
||||
- [Visibility](#visibility)
|
||||
- [Initial Super Call](#initial-super-call)
|
||||
- [Simple Modifications](#simple-modifications)
|
||||
- [Field Initialization](#field-initialization)
|
||||
- [Setter Bypass](#setter-bypass)
|
||||
- [Initialization Options](#initialization-options)
|
||||
- [Expression Level Transformation](#expression-level-transformation)
|
||||
- [TypeMap](#typemap)
|
||||
|
||||
<!-- END INDEX -->
|
||||
|
||||
# Macro API
|
||||
@@ -64,6 +64,8 @@ Rejects an expression and displays a generic or custom error message
|
||||
Converts an expression into the corresponding Haxe source code
|
||||
- `log(e:Expr, ?pos:Position):Expr`
|
||||
Traces the string representation of an expression and returns it.
|
||||
- `concat(e1:Expr, e2:Expr):Expr`
|
||||
Concats two expressions into a block. If either sub-expression is a block itself, it gets flattened into the resulting block.
|
||||
|
||||
#### Extracting Constants
|
||||
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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;}));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user