Skip to content

Commit

Permalink
Merge pull request #15 from AlexHaxe/dot_method_chains
Browse files Browse the repository at this point in the history
changed position of Dot in method chains
  • Loading branch information
AlexHaxe authored Jul 8, 2018
2 parents f27576f + f3291aa commit 9cfa392
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 15 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
4 changes: 2 additions & 2 deletions haxelib.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tokentree",
"version": "1.0.4",
"version": "1.0.5",
"description": "TokenTree library used by haxe-checkstyle",
"repository": {
"type": "git",
Expand Down
8 changes: 8 additions & 0 deletions src/tokentree/TokenTree.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/tokentree/walk/WalkClass.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/tokentree/walk/WalkFile.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
7 changes: 6 additions & 1 deletion src/tokentree/walk/WalkStatement.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions test/tokentree/walk/WalkIfTest.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
8 changes: 4 additions & 4 deletions test/tokentree/walk/WalkWhileTest.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit 9cfa392

Please sign in to comment.