Skip to content

Commit

Permalink
Merge pull request #13 from AlexHaxe/fix_comma_handling
Browse files Browse the repository at this point in the history
fix Comma handling
  • Loading branch information
AlexHaxe authored Jun 30, 2018
2 parents 03c8c87 + 6dd2641 commit 7a9e79f
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 28 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- Added support for haxeparser's whitespace (`-D keep_whitespace`) [#12](https://github.com/HaxeCheckstyle/tokentree/issues/12)
- Fixed handling of `if`, `while` and `do``while` conditions [#11](https://github.com/HaxeCheckstyle/tokentree/issues/11)
- Fixed handling of ternary expressions [#11](https://github.com/HaxeCheckstyle/tokentree/issues/11)
- Fixed tree position of `Comma` [#13](https://github.com/HaxeCheckstyle/tokentree/issues/13)

## version 1.0.3 (2018-06-24)

Expand Down
4 changes: 3 additions & 1 deletion src/tokentree/walk/WalkArrayAccess.hx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ class WalkArrayAccess {
tempStore = [];
case Comma:
var comma:TokenTree = stream.consumeTokenDef(Comma);
bkOpen.addChild(comma);
var child:TokenTree = bkOpen.getLastChild();
if (child == null) child = bkOpen;
child.addChild(comma);
default:
for (stored in tempStore) bkOpen.addChild(stored);
tempStore = [];
Expand Down
4 changes: 3 additions & 1 deletion src/tokentree/walk/WalkPOpen.hx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ class WalkPOpen {
WalkSharp.walkSharp(stream, parent, WalkPOpen.walkPOpenParts);
case Comma:
var comma:TokenTree = stream.consumeToken();
parent.addChild(comma);
var child:TokenTree = parent.getLastChild();
if (child == null) child = parent;
child.addChild(comma);
default:
WalkStatement.walkStatement(stream, parent);
}
Expand Down
2 changes: 1 addition & 1 deletion src/tokentree/walk/WalkStatement.hx
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class WalkStatement {
WalkDoWhile.walkDoWhile(stream, parent);
case Kwd(KwdWhile):
WalkWhile.walkWhile(stream, parent);
case Kwd(KwdNull):
case Kwd(KwdNull), Kwd(KwdTrue), Kwd(KwdFalse):
parent.addChild(stream.consumeToken());
return false;
default:
Expand Down
30 changes: 6 additions & 24 deletions src/tokentree/walk/WalkSwitch.hx
Original file line number Diff line number Diff line change
Expand Up @@ -120,33 +120,15 @@ class WalkSwitch {
var progress:TokenStreamProgress = new TokenStreamProgress(stream);
while (progress.streamHasChanged()) {
switch (stream.token()) {
case POpen:
WalkPOpen.walkPOpen(stream, parent);
case BrOpen:
WalkBlock.walkBlock(stream, parent);
case BkOpen:
WalkArrayAccess.walkArrayAccess(stream, parent);
case Kwd(KwdFunction):
WalkFunction.walkFunction(stream, parent, []);
case Kwd(KwdIf):
WalkIf.walkIf(stream, parent);
case Binop(OpGt):
var child:TokenTree = stream.consumeOpGt();
parent.addChild(child);
WalkSwitch.walkCaseExpr(stream, child);
case Binop(OpSub):
var child:TokenTree = stream.consumeOpSub();
parent.addChild(child);
WalkSwitch.walkCaseExpr(stream, child);
case Comma:
var comma:TokenTree = stream.consumeTokenDef(Comma);
var child:TokenTree = parent.getLastChild();
if (child == null) child = parent;
child.addChild(comma);
case Semicolon, BrClose, BkClose, PClose, DblDot:
return;
case Comment(_), CommentLine(_):
var child:TokenTree = stream.consumeToken();
parent.addChild(child);
default:
var child:TokenTree = stream.consumeToken();
parent.addChild(child);
WalkSwitch.walkCaseExpr(stream, child);
WalkStatement.walkStatement(stream, parent);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/tokentree/TokenTreeBuilderTest.hx
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ abstract TokenTreeBuilderTests(String) to String {
" POpen\n" +
" BkOpen\n" +
" Const(CString(checkstyle:MagicNumber))\n" +
" Comma\n" +
" Comma\n" +
" Const(CString(checkstyle:AvoidStarImport))\n" +
" BkClose\n" +
" PClose\n" +
Expand Down

0 comments on commit 7a9e79f

Please sign in to comment.