Skip to content

Commit

Permalink
added support for overload (#204)
Browse files Browse the repository at this point in the history
* added support for overload
* updated to latest haxeparser lib
  • Loading branch information
AlexHaxe authored Dec 20, 2020
1 parent 9b483ff commit 8d317ea
Show file tree
Hide file tree
Showing 15 changed files with 51 additions and 77 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

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

- Upgraded to latest haxeparser version ([#202](https://github.com/HaxeCheckstyle/tokentree/issues/202))
- Upgraded to latest haxeparser version ([#202](https://github.com/HaxeCheckstyle/tokentree/issues/202) + [#204](https://github.com/HaxeCheckstyle/tokentree/issues/204))
- Added testcases for ExpressionLevel code ([#202](https://github.com/HaxeCheckstyle/tokentree/issues/202))
- Added stream end detection to POpen and array access parsing ([#202](https://github.com/HaxeCheckstyle/tokentree/issues/202))
- Added overload support ([#204](https://github.com/HaxeCheckstyle/tokentree/issues/204))
- Fixed function type parameter ([#203](https://github.com/HaxeCheckstyle/tokentree/issues/203))
- Retired Haxe 3.4.7 compile support ([#202](https://github.com/HaxeCheckstyle/tokentree/issues/202))

Expand Down
35 changes: 0 additions & 35 deletions gruntfile.js

This file was deleted.

4 changes: 2 additions & 2 deletions haxe_libraries/haxeparser.hxml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# @install: lix --silent download "gh://github.com/Simn/haxeparser#563ab2e79b2eac4e029ac0f9f27e5a8fc37f15ba" into haxeparser/3.3.0/github/563ab2e79b2eac4e029ac0f9f27e5a8fc37f15ba
# @install: lix --silent download "gh://github.com/Simn/haxeparser#7649b016b86ff16676110a7cddcbe186a5101ca6" into haxeparser/3.3.0/github/7649b016b86ff16676110a7cddcbe186a5101ca6
-lib hxparse
-cp ${HAXE_LIBCACHE}/haxeparser/3.3.0/github/563ab2e79b2eac4e029ac0f9f27e5a8fc37f15ba/src
-cp ${HAXE_LIBCACHE}/haxeparser/3.3.0/github/7649b016b86ff16676110a7cddcbe186a5101ca6/src
-D haxeparser=3.3.0
6 changes: 3 additions & 3 deletions haxe_libraries/hxparse.hxml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
-D hxparse=4.0.0
# @install: lix --silent download "gh://github.com/Simn/hxparse#f61faa2021f2abb85360f997ff72c4156c891adc" into hxparse/4.0.0/github/f61faa2021f2abb85360f997ff72c4156c891adc
-cp ${HAXE_LIBCACHE}/hxparse/4.0.0/github/f61faa2021f2abb85360f997ff72c4156c891adc/src
# @install: lix --silent download "gh://github.com/Simn/hxparse#93f67419852e96daa2b81901c43a77e878c8c2bc" into hxparse/4.0.1/github/93f67419852e96daa2b81901c43a77e878c8c2bc
-cp ${HAXE_LIBCACHE}/hxparse/4.0.1/github/93f67419852e96daa2b81901c43a77e878c8c2bc/src
-D hxparse=4.0.1
4 changes: 2 additions & 2 deletions haxe_libraries/json2object.hxml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# @install: lix --silent download "haxelib:/json2object#3.8.1" into json2object/3.8.1/haxelib
# @install: lix --silent download "gh://github.com/elnabo/json2object#a6845b4826151271dd34c69631ffda0886abd562" into json2object/3.8.1/github/a6845b4826151271dd34c69631ffda0886abd562
-lib hxjsonast
-cp ${HAXE_LIBCACHE}/json2object/3.8.1/haxelib/src
-cp ${HAXE_LIBCACHE}/json2object/3.8.1/github/a6845b4826151271dd34c69631ffda0886abd562/src
-D json2object=3.8.1
3 changes: 0 additions & 3 deletions haxe_libraries/mconsole.hxml

This file was deleted.

5 changes: 0 additions & 5 deletions haxe_libraries/mcover.hxml

This file was deleted.

4 changes: 0 additions & 4 deletions haxe_libraries/mlib.hxml

This file was deleted.

6 changes: 0 additions & 6 deletions haxe_libraries/munit.hxml

This file was deleted.

4 changes: 2 additions & 2 deletions haxe_libraries/utest.hxml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# @install: lix --silent download "haxelib:/utest#1.13.1" into utest/1.13.1/haxelib
-cp ${HAXE_LIBCACHE}/utest/1.13.1/haxelib/src
# @install: lix --silent download "gh://github.com/haxe-utest/utest#7c0737bfe019afe1823b585597cd7851043e7dc1" into utest/1.13.1/github/7c0737bfe019afe1823b585597cd7851043e7dc1
-cp ${HAXE_LIBCACHE}/utest/1.13.1/github/7c0737bfe019afe1823b585597cd7851043e7dc1/src
-D utest=1.13.1
--macro utest.utils.Macro.checkHaxe()
--macro utest.utils.Macro.importEnvSettings()
6 changes: 3 additions & 3 deletions src/tokentree/walk/WalkClass.hx
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ class WalkClass {
break;
case Semicolon:
parent.addChild(stream.consumeToken());
case Kwd(KwdPublic), Kwd(KwdPrivate), Kwd(KwdStatic), Kwd(KwdInline), Kwd(KwdMacro), Kwd(KwdOverride), Kwd(KwdDynamic), Kwd(KwdExtern),
Kwd(KwdAbstract):
case Kwd(KwdPublic) | Kwd(KwdPrivate) | Kwd(KwdStatic) | Kwd(KwdInline) | Kwd(KwdMacro) | Kwd(KwdOverride) | Kwd(KwdDynamic) |
Kwd(KwdExtern) | Kwd(KwdAbstract) | Kwd(KwdOverload):
stream.consumeToTempStore();
case Kwd(KwdFinal):
WalkFinal.walkFinal(stream, parent);
case Comment(_), CommentLine(_):
case Comment(_) | CommentLine(_):
if (stream.hasTempStore()) {
stream.consumeToTempStore();
}
Expand Down
10 changes: 5 additions & 5 deletions src/tokentree/walk/WalkFile.hx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class WalkFile {
var progress:TokenStreamProgress = new TokenStreamProgress(stream);
while (stream.hasMore() && progress.streamHasChanged()) {
switch (stream.token()) {
case Kwd(KwdPackage), Kwd(KwdImport), Kwd(KwdUsing):
case Kwd(KwdPackage) | Kwd(KwdImport) | Kwd(KwdUsing):
stream.applyTempStore(parent);
WalkPackageImport.walkPackageImport(stream, parent);
case Sharp(_):
Expand All @@ -17,18 +17,18 @@ class WalkFile {
}
case At:
stream.addToTempStore(WalkAt.walkAt(stream));
case Comment(_), CommentLine(_):
case Comment(_) | CommentLine(_):
if (stream.hasTempStore()) {
stream.consumeToTempStore();
}
else {
WalkComment.walkComment(stream, parent);
}
case Kwd(KwdClass), Kwd(KwdInterface), Kwd(KwdEnum), Kwd(KwdTypedef), Kwd(KwdAbstract):
case Kwd(KwdClass) | Kwd(KwdInterface) | Kwd(KwdEnum) | Kwd(KwdTypedef) | Kwd(KwdAbstract):
WalkType.walkType(stream, parent);
case PClose, BrClose, BkClose, Semicolon, Comma:
parent.addChild(stream.consumeToken());
case Kwd(KwdPublic), Kwd(KwdPrivate), Kwd(KwdStatic), Kwd(KwdInline), Kwd(KwdMacro), Kwd(KwdDynamic), Kwd(KwdExtern):
case Kwd(KwdPublic) | Kwd(KwdPrivate) | Kwd(KwdStatic) | Kwd(KwdInline) | Kwd(KwdMacro) | Kwd(KwdDynamic) | Kwd(KwdExtern) | Kwd(KwdOverload):
stream.consumeToTempStore();
case Kwd(KwdFinal):
WalkFinal.walkFinal(stream, parent);
Expand All @@ -43,7 +43,7 @@ class WalkFile {
var tempStore:Array<TokenTree> = stream.getTempStore();
for (stored in tempStore) {
switch (stored.tok) {
case Kwd(KwdExtern), Kwd(KwdPrivate), Kwd(KwdPublic), At:
case Kwd(KwdExtern) | Kwd(KwdPrivate) | Kwd(KwdPublic) | At:
switch (TokenStream.MODE) {
case Relaxed: parent.addChild(stored);
case Strict: throw "invalid token tree structure - found:" + stored;
Expand Down
1 change: 0 additions & 1 deletion test.hxml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
-cp test

-lib haxeparser
-lib mcover
-lib utest
-lib instrument

Expand Down
36 changes: 32 additions & 4 deletions test/tokentree/TokenTreeBuilderParsingTest.hx
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ class TokenTreeBuilderParsingTest implements ITest {
assertCodeParses(DOLLAR_CHAIN);
assertCodeParses(TYPE_PARAM_WITH_ARRAY);
assertCodeParses(FUNCTION_TYPE_PARAM);
assertCodeParses(OVERLOAD_FUNCTION);
assertCodeParses(SPREAD_OPERATOR);
}

@Test
Expand Down Expand Up @@ -1694,11 +1696,37 @@ import #if haxe4 js.lib.Promise #else js.Promise #end as JsPromise;
var ARRAY_ACCESSS_WITHOUT_SEMICOLON = 'tokens[index]';

var FUNCTION_TYPE_PARAM = "
class Test {
public static function call(param1:String, param2:String, param3:String):Int {
var functionName:Function<(param1:String, param2:String, param3:String) -> Int, cpp.abi.Winapi> = Function.getProcAddress('some.dll', 'FunctionName');
return functionName(param1, param2, param3);
class Test {
public static function call(param1:String, param2:String, param3:String):Int {
var functionName:Function<(param1:String, param2:String, param3:String) -> Int, cpp.abi.Winapi> = Function.getProcAddress('some.dll', 'FunctionName');
return functionName(param1, param2, param3);
}
}
";

var OVERLOAD_FUNCTION = "
abstract class Foo {
static overload extern inline function foo() {}
overload static extern inline function foo(i:Int) {}
}
overload static inline function foo() {}
overload static inline function foo(i:Int) {}
";

var SPREAD_OPERATOR = "
class Foo {
function func(...r:Int) {}
function func(a:Int, ...r:Int) {}
function func(a:Int, ...r:Array<Int>) {}
function methodWithRest(rest:Rest<Int>):Rest<Int> {
return super.methodWithRest(...rest.append(999));
}
}
function func(...r:Int) {}
function func(a:Int, ...r:Int) {}
function func(a:Int, ...r:Array<Int>) {}
function methodWithRest(rest:Rest<Int>):Rest<Int> {
return super.methodWithRest(...rest.append(999));
}
";
}
1 change: 0 additions & 1 deletion testWithoutCoverage.hxml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
-cp test

-lib haxeparser
-lib mcover
-lib utest

-D unittest
Expand Down

0 comments on commit 8d317ea

Please sign in to comment.