diff --git a/CHANGELOG.md b/CHANGELOG.md index 4fe4456..397982d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,12 @@ ## dev branch / next version (1.x.x) +## version 1.0.5 (2018-07-08) + - Added support for `enum abstract` [#14](https://github.com/HaxeCheckstyle/tokentree/issues/14) - Added support for `@:a.b.c` [#14](https://github.com/HaxeCheckstyle/tokentree/issues/14) - Added support for `var ?x:Int` [#14](https://github.com/HaxeCheckstyle/tokentree/issues/14) - Added support for `extern` fields [#14](https://github.com/HaxeCheckstyle/tokentree/issues/14) +- Changed position of Dot in method chains [#15](https://github.com/HaxeCheckstyle/tokentree/issues/15) ## version 1.0.4 (2018-06-30) diff --git a/haxelib.json b/haxelib.json index 0822223..ea4fb02 100644 --- a/haxelib.json +++ b/haxelib.json @@ -7,8 +7,8 @@ "contributors": [ "AlexHaxe" ], - "releasenote": "Added parent and sibling access methods to TokenTreeAccessHelper - see CHANGELOG", - "version": "1.0.4", + "releasenote": "Added support for some Haxe 4 syntax changes - see CHANGELOG", + "version": "1.0.5", "url": "https://github.com/HaxeCheckstyle/tokentree", "dependencies": {} } \ No newline at end of file diff --git a/package.json b/package.json index bdd5aae..3db9017 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tokentree", - "version": "1.0.4", + "version": "1.0.5", "description": "TokenTree library used by haxe-checkstyle", "repository": { "type": "git", diff --git a/src/tokentree/TokenTree.hx b/src/tokentree/TokenTree.hx index 3133a4f..0baf46a 100644 --- a/src/tokentree/TokenTree.hx +++ b/src/tokentree/TokenTree.hx @@ -34,6 +34,14 @@ class TokenTree extends Token { } } + public function isCIdent():Bool { + if (tok == null) return false; + return switch (tok) { + case Const(CIdent(_)): true; + default: false; + } + } + public function addChild(child:TokenTree) { if (children == null) children = []; if (children.length > 0) { diff --git a/src/tokentree/walk/WalkClass.hx b/src/tokentree/walk/WalkClass.hx index 41ce4f4..40d67a1 100644 --- a/src/tokentree/walk/WalkClass.hx +++ b/src/tokentree/walk/WalkClass.hx @@ -64,14 +64,14 @@ class WalkClass { default: switch (TokenStream.MODE) { case RELAXED: WalkStatement.walkStatement(stream, parent); - case STRICT: throw "invalid token tree structure"; + case STRICT: throw "invalid token tree structure - found:" + '${stream.token()}'; } } } if (tempStore.length > 0) { switch (TokenStream.MODE) { case RELAXED: for (tok in tempStore) parent.addChild(tok); - case STRICT: throw "invalid token tree structure"; + case STRICT: throw "invalid token tree structure - found:" + '$tempStore'; } } } diff --git a/src/tokentree/walk/WalkFile.hx b/src/tokentree/walk/WalkFile.hx index e51771e..d86bf98 100644 --- a/src/tokentree/walk/WalkFile.hx +++ b/src/tokentree/walk/WalkFile.hx @@ -37,7 +37,7 @@ class WalkFile { case Kwd(KwdExtern), Kwd(KwdPrivate), Kwd(KwdPublic), At: switch (TokenStream.MODE) { case RELAXED: parent.addChild(stored); - case STRICT: throw "invalid token tree structure"; + case STRICT: throw "invalid token tree structure - found:" + stored; } default: parent.addChild(stored); } diff --git a/src/tokentree/walk/WalkStatement.hx b/src/tokentree/walk/WalkStatement.hx index e6e8b95..bb960d0 100644 --- a/src/tokentree/walk/WalkStatement.hx +++ b/src/tokentree/walk/WalkStatement.hx @@ -48,7 +48,12 @@ class WalkStatement { return; case POpen: var pOpen:TokenTree = WalkPOpen.walkPOpen(stream, parent); - WalkStatement.walkStatementContinue(stream, pOpen); + if (parent.isCIdent()) { + WalkStatement.walkStatementContinue(stream, parent); + } + else { + WalkStatement.walkStatementContinue(stream, pOpen); + } return; case Question: WalkQuestion.walkQuestion(stream, parent); diff --git a/test/tokentree/walk/WalkIfTest.hx b/test/tokentree/walk/WalkIfTest.hx index b1bf19a..684d8d0 100644 --- a/test/tokentree/walk/WalkIfTest.hx +++ b/test/tokentree/walk/WalkIfTest.hx @@ -60,15 +60,15 @@ class WalkIfTest extends VerifyTokenTreeBase { var ifTok:IVerifyTokenTree = root.oneChild().first().is(Kwd(KwdIf)).childCount(2); ifTok.first().is(Const(CIdent("test"))).oneChild().first().is(Binop(OpBoolAnd)).oneChild().first().is(Const(CIdent("test2"))).noChilds(); - var exprCall:IVerifyTokenTree = ifTok.last().is(Const(CIdent("doSomething"))).oneChild().first().is(POpen).childCount(2); - exprCall.first().is(PClose).noChilds(); + var exprCall:IVerifyTokenTree = ifTok.last().is(Const(CIdent("doSomething"))).childCount(2); + exprCall.first().is(POpen).oneChild().first().is(PClose).noChilds(); exprCall.last().is(Semicolon).noChilds(); } function testifBody(ifTok:IVerifyTokenTree) { var ifBody:IVerifyTokenTree = ifTok.last().is(BrOpen).childCount(2); - var exprCall:IVerifyTokenTree = ifBody.first().is(Const(CIdent("doSomething"))).oneChild().first().is(POpen).childCount(2); - exprCall.first().is(PClose).noChilds(); + var exprCall:IVerifyTokenTree = ifBody.first().is(Const(CIdent("doSomething"))).childCount(2); + exprCall.first().is(POpen).oneChild().first().is(PClose).noChilds(); exprCall.last().is(Semicolon).noChilds(); ifBody.last().is(BrClose).noChilds(); } diff --git a/test/tokentree/walk/WalkWhileTest.hx b/test/tokentree/walk/WalkWhileTest.hx index 939c7c0..e1a348e 100644 --- a/test/tokentree/walk/WalkWhileTest.hx +++ b/test/tokentree/walk/WalkWhileTest.hx @@ -60,15 +60,15 @@ class WalkWhileTest extends VerifyTokenTreeBase { var whileTok:IVerifyTokenTree = root.oneChild().first().is(Kwd(KwdWhile)).childCount(2); whileTok.first().is(Const(CIdent("test"))).oneChild().first().is(Binop(OpBoolAnd)).oneChild().first().is(Const(CIdent("test2"))).noChilds(); - var exprCall:IVerifyTokenTree = whileTok.last().is(Const(CIdent("doSomething"))).oneChild().first().is(POpen).childCount(2); - exprCall.first().is(PClose).noChilds(); + var exprCall:IVerifyTokenTree = whileTok.last().is(Const(CIdent("doSomething"))).childCount(2); + exprCall.first().is(POpen).oneChild().first().is(PClose).noChilds(); exprCall.last().is(Semicolon).noChilds(); } function testWhileBody(whileTok:IVerifyTokenTree) { var ifBody:IVerifyTokenTree = whileTok.last().is(BrOpen).childCount(2); - var exprCall:IVerifyTokenTree = ifBody.first().is(Const(CIdent("doSomething"))).oneChild().first().is(POpen).childCount(2); - exprCall.first().is(PClose).noChilds(); + var exprCall:IVerifyTokenTree = ifBody.first().is(Const(CIdent("doSomething"))).childCount(2); + exprCall.first().is(POpen).oneChild().first().is(PClose).noChilds(); exprCall.last().is(Semicolon).noChilds(); ifBody.last().is(BrClose).noChilds(); }