From 08fd5d6dd2fc608ddefd9ef49e2d435f1bbce901 Mon Sep 17 00:00:00 2001 From: AlexHaxe Date: Mon, 13 Aug 2018 19:11:58 +0200 Subject: [PATCH] fix endless loop with case in block (#93) * fix endless loop with case in block * prepare release 1.0.9 --- CHANGELOG.md | 4 ++++ haxelib.json | 4 ++-- package.json | 2 +- src/tokentree/walk/WalkBlock.hx | 2 ++ src/tokentree/walk/WalkSwitch.hx | 15 +++++++++++---- test/tokentree/TokenTreeBuilderParsingTest.hx | 19 +++++++++++++++++++ 6 files changed, 39 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 26fa4cc..50eee1a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## dev branch / next version (1.x.x) +## version 1.0.9 (2018-08-13) + +- Fixed endless loop with case and conditionals [#93](https://github.com/HaxeCheckstyle/tokentree/issues/93) + ## version 1.0.8 (2018-08-13) - Fixed null poiner and detection in `getPOpenType` [#73](https://github.com/HaxeCheckstyle/tokentree/issues/73) + [#88](https://github.com/HaxeCheckstyle/tokentree/issues/88) + [#91](https://github.com/HaxeCheckstyle/tokentree/issues/91) diff --git a/haxelib.json b/haxelib.json index 9c1f0b7..a47fe5a 100644 --- a/haxelib.json +++ b/haxelib.json @@ -7,8 +7,8 @@ "contributors": [ "AlexHaxe" ], - "releasenote": "fixed POpen and BrOpen type detection, fixed endless loop with switch and conditionals - see CHANGELOG for details", - "version": "1.0.8", + "releasenote": "fixed endless loop with switch and conditionals - see CHANGELOG for details", + "version": "1.0.9", "url": "https://github.com/HaxeCheckstyle/tokentree", "dependencies": {} } \ No newline at end of file diff --git a/package.json b/package.json index ccdfb8d..1aadbd3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tokentree", - "version": "1.0.8", + "version": "1.0.9", "description": "TokenTree library used by haxe-checkstyle", "repository": { "type": "git", diff --git a/src/tokentree/walk/WalkBlock.hx b/src/tokentree/walk/WalkBlock.hx index 47ac1d0..9b45d8c 100644 --- a/src/tokentree/walk/WalkBlock.hx +++ b/src/tokentree/walk/WalkBlock.hx @@ -41,6 +41,8 @@ class WalkBlock { case BkClose, PClose: var child:TokenTree = stream.consumeToken(); parent.addChild(child); + case Kwd(KwdCase), Kwd(KwdDefault): + WalkSwitch.walkSwitchCases(stream, parent); default: WalkStatement.walkStatement(stream, parent); } diff --git a/src/tokentree/walk/WalkSwitch.hx b/src/tokentree/walk/WalkSwitch.hx index d1bb4a9..cfd4ad7 100644 --- a/src/tokentree/walk/WalkSwitch.hx +++ b/src/tokentree/walk/WalkSwitch.hx @@ -28,10 +28,17 @@ class WalkSwitch { WalkComment.walkComment(stream, switchTok); WalkStatement.walkStatement(stream, switchTok); WalkComment.walkComment(stream, switchTok); - var brOpen:TokenTree = stream.consumeTokenDef(BrOpen); - switchTok.addChild(brOpen); - WalkSwitch.walkSwitchCases(stream, brOpen); - brOpen.addChild(stream.consumeTokenDef(BrClose)); + switch (stream.token()) { + case Sharp(_): + WalkSharp.walkSharp(stream, parent, WalkSwitch.walkSwitchCases); + default: + } + if (stream.is(BrOpen)) { + var brOpen:TokenTree = stream.consumeTokenDef(BrOpen); + switchTok.addChild(brOpen); + WalkSwitch.walkSwitchCases(stream, brOpen); + brOpen.addChild(stream.consumeTokenDef(BrClose)); + } } public static function walkSwitchCases(stream:TokenStream, parent:TokenTree) { diff --git a/test/tokentree/TokenTreeBuilderParsingTest.hx b/test/tokentree/TokenTreeBuilderParsingTest.hx index 0c6730e..0e50a85 100644 --- a/test/tokentree/TokenTreeBuilderParsingTest.hx +++ b/test/tokentree/TokenTreeBuilderParsingTest.hx @@ -866,6 +866,25 @@ abstract TokenTreeBuilderParsingTests(String) to String { Sys.println (' succedded'); } } + public static function main() { + #if neko + switch (Sys.command ('neko', ['tests.n', name, field.name])) + #elseif cpp + switch (Sys.command ('./bin/FunctionalTest', [name, field.name])) + #end { + case 0: + passed++; + Sys.println (' succedded'); + #if neko + case 1: + Sys.println(' failed'); + #end + case 1: + Sys.println(' failed'); + case _: + Sys.println(' errored'); + } + } } "; } \ No newline at end of file