Skip to content

Commit

Permalink
fixed type parameter detection
Browse files Browse the repository at this point in the history
fixed Dollar handling
  • Loading branch information
AlexHaxe committed Nov 2, 2020
1 parent 386bcb8 commit 90684a4
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
## dev branch / next version (1.x.x)

- Fixed arrow functions
- Fixed type parameter detection
- Fixed Dollar handling


## version 1.0.29 (2020-11-01)
Expand Down
1 change: 1 addition & 0 deletions checkstyle.json
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@
"tokentree/utils/TokenTreeCheckUtils:determinBrChildren",
"tokentree/utils/TokenTreeCheckUtils:findColonParent",
"tokentree/ToTokenTreeDef",
"tokentree/TokenStream:isTypedParam",
"tokentree/TokenTreeDefPrinter"
],
"MethodLength": [
Expand Down
29 changes: 27 additions & 2 deletions src/tokentree/TokenStream.hx
Original file line number Diff line number Diff line change
Expand Up @@ -141,21 +141,46 @@ class TokenStream {
default:
return false;
}
var depth:Int = 1;
var brDepth:Int = 0;
var pDepth:Int = 0;
while (true) {
token = tokens[index++];
switch (token.tok) {
case Dot:
case DblDot:
case Comma:
case Arrow:
case POpen:
pDepth++;
case PClose:
if (pDepth <= 0) {
return false;
}
pDepth--;
case BrOpen:
brDepth++;
case BrClose:
if (brDepth <= 0) {
return false;
}
brDepth--;
case Const(_):
case Kwd(_):
// case Kwd(_):
case Dollar(_):
case Binop(OpLt):
depth++;
case Binop(OpGt):
return true;
depth--;
if (depth <= 0) {
return true;
}
default:
return false;
}
if (index >= tokens.length) {
return false;
}
}
return false;
}
Expand Down
2 changes: 2 additions & 0 deletions src/tokentree/walk/WalkLtGt.hx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class WalkLtGt {
var dblDot:TokenTree = stream.consumeToken();
ltTok.addChild(dblDot);
WalkTypeNameDef.walkTypeNameDef(stream, ltTok);
case POpen:
WalkPOpen.walkPOpen(stream, ltTok);
default:
WalkFieldDef.walkFieldDef(stream, ltTok);
}
Expand Down
14 changes: 13 additions & 1 deletion src/tokentree/walk/WalkStatement.hx
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ class WalkStatement {
parent.addChild(newChild);
stream.applyTempStore(newChild);
walkTrailingComment(stream, newChild);

if (wantMore) walkStatementWithoutSemicolon(stream, newChild);
walkStatementContinue(stream, newChild);
walkTrailingComment(stream, newChild);
Expand Down Expand Up @@ -169,6 +170,17 @@ class WalkStatement {
walkOpBool(stream, parent);
case Binop(OpAdd), Binop(OpSub):
walkOpAdd(stream, parent);
case Binop(OpGt):
var ltParent:TokenTree = parent;
while (true) {
switch (ltParent.tok) {
case Root: break;
case Dot | DblDot | Comma | Arrow | POpen | Const(_) | Dollar(_) | Binop(OpGt): ltParent = ltParent.parent;
case Binop(OpLt): return;
default: break;
}
}
walkStatementWithoutSemicolon(stream, parent);
case Binop(_):
walkStatementWithoutSemicolon(stream, parent);
case Const(CIdent("is")):
Expand Down Expand Up @@ -445,7 +457,7 @@ class WalkStatement {
var dollarTok:TokenTree = stream.consumeToken();
parent.addChild(dollarTok);
switch (stream.token()) {
case POpen | BrOpen | BkOpen | Binop(_) | Const(CIdent("is")):
case POpen | BrOpen | BkOpen | Dot | Binop(_) | Const(CIdent("is")):
WalkBlock.walkBlock(stream, dollarTok);
default:
}
Expand Down
25 changes: 25 additions & 0 deletions test/tokentree/TokenTreeBuilderParsingTest.hx
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ class TokenTreeBuilderParsingTest implements ITest {
assertCodeParses(SEMICOLON_BINOP);
assertCodeParses(NEW_ARRAY_ACCESS);
assertCodeParses(MACRO_COMPLEXTYPE);
assertCodeParses(CALLBACK_TYPE_PARAM);
assertCodeParses(MAP_INIT_WITH_COMMENT);
assertCodeParses(DOLLAR_CHAIN);
}

public function assertCodeParses(code:String, ?pos:PosInfos) {
Expand Down Expand Up @@ -1643,4 +1646,26 @@ import #if haxe4 js.lib.Promise #else js.Promise #end as JsPromise;
class Test {
var retType = macro : Map<String, String>;
}";

var CALLBACK_TYPE_PARAM = "
class HaxeServer {
var stopProgressCallback:Null<() -> Void>;
}";

var MAP_INIT_WITH_COMMENT = "
final flags = [
CompilationServer => [
// server
],
];";

var DOLLAR_CHAIN = "
class Main {
function foobar() {
assignments.push(macro {
if ($struct.$name == null)
$struct.$name = $defaults.$name;
});
}
}";
}

0 comments on commit 90684a4

Please sign in to comment.