Skip to content

Commit

Permalink
fixed conditionals using dot idents without parens (#159)
Browse files Browse the repository at this point in the history
* fixed conditionals using dot idents without parens
  • Loading branch information
AlexHaxe authored May 30, 2019
1 parent 78b0ba1 commit 3067f45
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ matrix:
- yes | haxelib git haxeparser https://github.com/simn/haxeparser
- haxelib install compiletime 2.6.0
- haxelib install hxargs 3.0.2
- haxelib git mcover https://github.com/AlexHaxe/mcover haxe_4_thread src
- haxelib install munit
- haxelib install mcover
- haxelib install mconsole
- haxelib git hxnodejs https://github.com/HaxeFoundation/hxnodejs.git master
- haxelib install test-adapter
Expand All @@ -34,9 +34,9 @@ matrix:
install:
- haxelib git hxparse https://github.com/simn/hxparse
- yes | haxelib git haxeparser https://github.com/simn/haxeparser
- haxelib git mcover https://github.com/AlexHaxe/mcover haxe_4_thread src
- haxelib git munit https://github.com/AlexHaxe/MassiveUnit.git haxe_4_thread src
- haxelib git hxnodejs https://github.com/HaxeFoundation/hxnodejs.git master
- haxelib install munit
- haxelib install mcover
- haxelib install mlib
- haxelib install mconsole
- haxelib install compiletime 2.6.0
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## dev branch / next version (1.x.x)

- Fixed conditionals using dot idents without parens [#159](https://github.com/HaxeCheckstyle/tokentree/issues/159)

## version 1.0.20 (2019-05-17)

- Fixed potential null pointer in `TokenTreeAccessHelper.findParent` [#157](https://github.com/HaxeCheckstyle/tokentree/issues/157)
Expand Down
12 changes: 12 additions & 0 deletions src/tokentree/walk/WalkSharp.hx
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,18 @@ class WalkSharp {
case Kwd(_), Const(CIdent(_)):
childToken = stream.consumeToken();
parent.addChild(childToken);
if (!stream.hasMore()) return;
switch (stream.token()) {
case Dot:
default: return;
}
var pos:Null<Position> = stream.getTokenPos();
if (pos == null) return;
if (pos.min == childToken.pos.max + 1) continue;

var dot:TokenTree = stream.consumeToken();
childToken.addChild(dot);
WalkSharp.walkSharpIfExpr(stream, dot);
return;
default:
return;
Expand Down
11 changes: 11 additions & 0 deletions test/tokentree/TokenTreeBuilderParsingTest.hx
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class TokenTreeBuilderParsingTest {
assertCodeParses(TERNARY_WITH_RETURN);
assertCodeParses(TRY_CATCH_WITH_COMMENT);
assertCodeParses(TERNARY_WITH_OP_BOOL);
assertCodeParses(DOT_IDENT_CONDITIONAL);
}

public function assertCodeParses(code:String, ?pos:PosInfos) {
Expand Down Expand Up @@ -1343,4 +1344,14 @@ abstract TokenTreeBuilderParsingTests(String) to String {
}
}
";

var DOT_IDENT_CONDITIONAL = "
class Main {
static function main() {
#if target.sys
trace('Test');
#end
}
}
";
}

0 comments on commit 3067f45

Please sign in to comment.