From 241919549cb7e782f04da2a8f4b9e45257354e29 Mon Sep 17 00:00:00 2001 From: kevinresol Date: Sun, 21 Aug 2016 15:02:42 +0800 Subject: [PATCH 1/5] Add concat() --- src/tink/macro/Exprs.hx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/tink/macro/Exprs.hx b/src/tink/macro/Exprs.hx index 7f68fe2..6dfb87f 100644 --- a/src/tink/macro/Exprs.hx +++ b/src/tink/macro/Exprs.hx @@ -388,10 +388,18 @@ class Exprs { case EFunction(_, f): Success(f); default: e.pos.makeFailure(NOT_A_FUNCTION); } + + static public function concat(e:Expr, with:Expr, ?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); + } static inline var NOT_AN_INT = "integer constant expected"; static inline var NOT_AN_IDENT = "identifier expected"; static inline var NOT_A_STRING = "string constant expected"; static inline var NOT_A_NAME = "name expected"; static inline var NOT_A_FUNCTION = "function expected"; + static inline var NOT_A_BLOCK = "block expected"; } From 38aa0f4dc49c77a142c9874a80930e0904c45648 Mon Sep 17 00:00:00 2001 From: Kevin Leung Date: Wed, 7 Dec 2016 10:08:47 +0800 Subject: [PATCH 2/5] Concat any exprs --- src/tink/macro/Exprs.hx | 10 +++++++--- tests/Exprs.hx | 7 +++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/tink/macro/Exprs.hx b/src/tink/macro/Exprs.hx index 6dfb87f..5d509af 100644 --- a/src/tink/macro/Exprs.hx +++ b/src/tink/macro/Exprs.hx @@ -389,12 +389,16 @@ 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"; static inline var NOT_AN_IDENT = "identifier expected"; diff --git a/tests/Exprs.hx b/tests/Exprs.hx index 5fd2bf0..3b66feb 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).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()); + } } \ No newline at end of file From f0d5d80266dbd543b24547296bba7194b6bbc2ea Mon Sep 17 00:00:00 2001 From: Kevin Leung Date: Wed, 7 Dec 2016 10:09:20 +0800 Subject: [PATCH 3/5] Remove unused error message --- src/tink/macro/Exprs.hx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/tink/macro/Exprs.hx b/src/tink/macro/Exprs.hx index 5d509af..641f105 100644 --- a/src/tink/macro/Exprs.hx +++ b/src/tink/macro/Exprs.hx @@ -405,5 +405,4 @@ class Exprs { static inline var NOT_A_STRING = "string constant expected"; static inline var NOT_A_NAME = "name expected"; static inline var NOT_A_FUNCTION = "function expected"; - static inline var NOT_A_BLOCK = "block expected"; } From aad311f524d427fe999a454575db3faecb638eb0 Mon Sep 17 00:00:00 2001 From: Kevin Leung Date: Wed, 7 Dec 2016 10:10:22 +0800 Subject: [PATCH 4/5] Don't even need an outcome --- src/tink/macro/Exprs.hx | 8 ++++---- tests/Exprs.hx | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/tink/macro/Exprs.hx b/src/tink/macro/Exprs.hx index 641f105..410b107 100644 --- a/src/tink/macro/Exprs.hx +++ b/src/tink/macro/Exprs.hx @@ -393,10 +393,10 @@ class Exprs { if(pos == null) pos = e.pos; return switch [e.expr, with.expr] { - 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)); + 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); } } diff --git a/tests/Exprs.hx b/tests/Exprs.hx index 3b66feb..bb4a5f7 100644 --- a/tests/Exprs.hx +++ b/tests/Exprs.hx @@ -82,9 +82,9 @@ 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()); + 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 From d851094aa34912829570c579012d9d8ed9b3615f Mon Sep 17 00:00:00 2001 From: Juraj Kirchheim Date: Wed, 7 Dec 2016 06:44:36 +0100 Subject: [PATCH 5/5] Update README.md --- README.md | 58 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 8fbc3b7..3c73085 100644 --- a/README.md +++ b/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: - -- [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) - + +- [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) + # 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