From efbacf93eb7af0c992e6fde308f6f7575800c9f7 Mon Sep 17 00:00:00 2001 From: AlexHaxe Date: Wed, 14 Sep 2022 23:33:43 +0200 Subject: [PATCH] updated haxeparser to support latest Haxe nightly syntax (#657) * updated haxeparser and tokentree to support latest Haxe nightly syntax * only run tests on nightly because suffixes test fails on 4.2.5 --- .github/workflows/formatter.yml | 4 +- CHANGELOG.md | 4 + haxe_libraries/haxeparser.hxml | 6 +- haxe_libraries/hxparse.hxml | 6 +- haxe_libraries/tokentree.hxml | 6 +- haxelib.json | 4 +- package-lock.json | 4 +- package.json | 2 +- src/formatter/marker/MarkWhitespace.hx | 6 +- test/testcases/other/numeric_separator.hxtest | 169 ++++++++++++++++++ 10 files changed, 194 insertions(+), 17 deletions(-) create mode 100644 test/testcases/other/numeric_separator.hxtest diff --git a/.github/workflows/formatter.yml b/.github/workflows/formatter.yml index a19b675..6bdbd33 100644 --- a/.github/workflows/formatter.yml +++ b/.github/workflows/formatter.yml @@ -14,7 +14,7 @@ jobs: build: strategy: matrix: - haxe-version: ['4.0.5', '4.1.5', '4.2.5', 'nightly'] + haxe-version: ['4.2.5', 'nightly'] platform: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.platform }} steps: @@ -51,8 +51,10 @@ jobs: - name: Build JSON schema run: npx haxe buildSchema.hxml - name: Run eval tests + if: (matrix.haxe-version == 'nightly') run: npx haxe -D codecov_json test.hxml - name: Run Java tests + if: (matrix.haxe-version == 'nightly') run: npx haxe -D codecov_json testJava.hxml - name: Run Node version with --check run: node run.js -s . --check diff --git a/CHANGELOG.md b/CHANGELOG.md index 06786a0..3cdf28c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## dev branch / next version (1.x.x) +## version 1.14.2 (2022-09-14) + +- Updated haxeparser to support latest Haxe nightly syntax ([#657](https://github.com/HaxeCheckstyle/haxe-formatter/issues/657)) + ## version 1.14.1 (2022-09-07) - Improved support for inline markup ([#656](https://github.com/HaxeCheckstyle/haxe-formatter/issues/656)) diff --git a/haxe_libraries/haxeparser.hxml b/haxe_libraries/haxeparser.hxml index c6046d1..42b3c71 100644 --- a/haxe_libraries/haxeparser.hxml +++ b/haxe_libraries/haxeparser.hxml @@ -1,4 +1,4 @@ -# @install: lix --silent download "gh://github.com/HaxeCheckstyle/haxeparser#1ea2a8915956ac3af6f1a11c67e0e56261b75929" into haxeparser/3.3.0/github/1ea2a8915956ac3af6f1a11c67e0e56261b75929 +# @install: lix --silent download "gh://github.com/HaxeCheckstyle/haxeparser#f0a7f07101c14dc32b0964dd52af8dcaa322e178" into haxeparser/4.3.0-rc.1/github/f0a7f07101c14dc32b0964dd52af8dcaa322e178 -lib hxparse --cp ${HAXE_LIBCACHE}/haxeparser/3.3.0/github/1ea2a8915956ac3af6f1a11c67e0e56261b75929/src --D haxeparser=3.3.0 \ No newline at end of file +-cp ${HAXE_LIBCACHE}/haxeparser/4.3.0-rc.1/github/f0a7f07101c14dc32b0964dd52af8dcaa322e178/src +-D haxeparser=4.3.0-rc.1 \ No newline at end of file diff --git a/haxe_libraries/hxparse.hxml b/haxe_libraries/hxparse.hxml index c1c0c6d..a802671 100644 --- a/haxe_libraries/hxparse.hxml +++ b/haxe_libraries/hxparse.hxml @@ -1,3 +1,3 @@ -# @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 +# @install: lix --silent download "gh://github.com/simn/hxparse#32e376f80c4b0e999e9f3229947d4dac2138382b" into hxparse/4.0.1/github/32e376f80c4b0e999e9f3229947d4dac2138382b +-cp ${HAXE_LIBCACHE}/hxparse/4.0.1/github/32e376f80c4b0e999e9f3229947d4dac2138382b/src +-D hxparse=4.0.1 \ No newline at end of file diff --git a/haxe_libraries/tokentree.hxml b/haxe_libraries/tokentree.hxml index f91fbcc..70d059a 100644 --- a/haxe_libraries/tokentree.hxml +++ b/haxe_libraries/tokentree.hxml @@ -1,3 +1,3 @@ -# @install: lix --silent download "haxelib:/tokentree#1.2.1" into tokentree/1.2.1/haxelib --cp ${HAXE_LIBCACHE}/tokentree/1.2.1/haxelib/src --D tokentree=1.2.1 \ No newline at end of file +# @install: lix --silent download "haxelib:/tokentree#1.2.3" into tokentree/1.2.3/haxelib +-cp ${HAXE_LIBCACHE}/tokentree/1.2.3/haxelib/src +-D tokentree=1.2.3 \ No newline at end of file diff --git a/haxelib.json b/haxelib.json index 55e22cf..a6c9d69 100644 --- a/haxelib.json +++ b/haxelib.json @@ -8,8 +8,8 @@ "style" ], "description": "A code formatter for Haxe", - "version": "1.14.1", - "releasenote": "improved support for inline markup - see CHANGELOG for details.", + "version": "1.14.2", + "releasenote": "updated haxeparser to support latest Haxe nightly syntax - see CHANGELOG for details.", "contributors": [ "AlexHaxe", "Gama11" diff --git a/package-lock.json b/package-lock.json index 93e38b2..a4122d2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@haxecheckstyle/haxe-formatter", - "version": "1.14.1", + "version": "1.14.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@haxecheckstyle/haxe-formatter", - "version": "1.14.1", + "version": "1.14.2", "license": "MIT", "bin": { "haxe-formatter": "bin/formatter.js" diff --git a/package.json b/package.json index 6fa046b..58ffb3e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@haxecheckstyle/haxe-formatter", - "version": "1.14.1", + "version": "1.14.2", "description": "A code formatter for Haxe", "repository": { "type": "git", diff --git a/src/formatter/marker/MarkWhitespace.hx b/src/formatter/marker/MarkWhitespace.hx index 546f958..580dc8b 100644 --- a/src/formatter/marker/MarkWhitespace.hx +++ b/src/formatter/marker/MarkWhitespace.hx @@ -15,7 +15,7 @@ class MarkWhitespace extends MarkerBase { } case Binop(OpGt): markGt(token); - case Binop(OpInterval): + case Spread | Binop(OpInterval): markOpSpread(token); case Binop(OpIn): markIn(token); @@ -203,7 +203,7 @@ class MarkWhitespace extends MarkerBase { var prev:Null = getPreviousToken(token); if (prev != null) { switch (prev.token.tok) { - case POpen, BrOpen, BkOpen, IntInterval(_), Binop(OpInterval): + case POpen | BrOpen | BkOpen | IntInterval(_) | Spread | Binop(OpInterval): policy = policy.remove(Before); case PClose: switch (TokenTreeCheckUtils.getPOpenType(prev.token)) { @@ -760,6 +760,7 @@ class MarkWhitespace extends MarkerBase { return; case Dot: case DblDot: + case QuestionDot: case Arrow: case Comma: case BkOpen, BrOpen, POpen: @@ -771,6 +772,7 @@ class MarkWhitespace extends MarkerBase { case At: case Eof: return; + case Spread: } whitespace(token, Before); } diff --git a/test/testcases/other/numeric_separator.hxtest b/test/testcases/other/numeric_separator.hxtest new file mode 100644 index 0000000..b385e0b --- /dev/null +++ b/test/testcases/other/numeric_separator.hxtest @@ -0,0 +1,169 @@ +{} + +--- + +public function test() { + // normal int + eq(12_0, 120); + eq(1_2_0, 120); + + // hex int + eq(0x12_0, 0x120); + eq(0x1_2_0, 0x120); + + // normal float + feq(12.3_4, 12.34); + feq(1_2.34, 12.34); + feq(1_2.3_4, 12.34); + + // dot float + feq(.3_4, .34); + feq(.3_4_5, .345); + + // science float + feq(1_2e3_4, 12e34); + feq(1_2.3e4_5, 12.3e45); + + // int but actually float + feq(1_2f64, 12f64); +} + +public function testWithSuffix() { + // normal int + eq(12_0i32, 120i32); + eq(1_2_0i32, 120i32); + + // hex int + eq(0x12_0i32, 0x120i32); + eq(0x1_2_0i32, 0x120i32); + + // normal float + feq(12.3_4f64, 12.34f64); + feq(1_2.34f64, 12.34f64); + feq(1_2.3_4f64, 12.34f64); + + // dot float + feq(.3_4f64, .34f64); + feq(.3_4_5f64, .345f64); + + // science float + feq(1_2e3_4f64, 12e34f64); + feq(1_2.3e4_5f64, 12.3e45f64); +} + +public function testJustBeforeSuffix() { + // normal int + eq(12_0_i32, 120i32); + eq(1_2_0_i32, 120i32); + + // hex int + eq(0x12_0_i32, 0x120i32); + eq(0x1_2_0_i32, 0x120i32); + + // normal float + feq(12.3_4_f64, 12.34f64); + feq(1_2.34_f64, 12.34f64); + feq(1_2.3_4_f64, 12.34f64); + + // dot float + feq(.3_4_f64, .34f64); + feq(.3_4_5_f64, .345f64); + + // science float + feq(1_2e3_4_f64, 12e34f64); + feq(1_2.3e4_5_f64, 12.3e45f64); + + feq(1_2e-3_4_f64, 12e-34f64); + feq(1_2.3e-4_5_f64, 12.3e-45f64); + feq(1_2e+3_4_f64, 12e+34f64); + feq(1_2.3e+4_5_f64, 12.3e+45f64); + + feq(-1_2e-3_4_f64, -12e-34f64); + feq(-1_2.3e-4_5_f64, -12.3e-45f64); + feq(-1_2e+3_4_f64, -12e+34f64); + feq(-1_2.3e+4_5_f64, -12.3e+45f64); +} + +--- + +public function test() { + // normal int + eq(12_0, 120); + eq(1_2_0, 120); + + // hex int + eq(0x12_0, 0x120); + eq(0x1_2_0, 0x120); + + // normal float + feq(12.3_4, 12.34); + feq(1_2.34, 12.34); + feq(1_2.3_4, 12.34); + + // dot float + feq(.3_4, .34); + feq(.3_4_5, .345); + + // science float + feq(1_2e3_4, 12e34); + feq(1_2.3e4_5, 12.3e45); + + // int but actually float + feq(1_2f64, 12f64); +} + +public function testWithSuffix() { + // normal int + eq(12_0i32, 120i32); + eq(1_2_0i32, 120i32); + + // hex int + eq(0x12_0i32, 0x120i32); + eq(0x1_2_0i32, 0x120i32); + + // normal float + feq(12.3_4f64, 12.34f64); + feq(1_2.34f64, 12.34f64); + feq(1_2.3_4f64, 12.34f64); + + // dot float + feq(.3_4f64, .34f64); + feq(.3_4_5f64, .345f64); + + // science float + feq(1_2e3_4f64, 12e34f64); + feq(1_2.3e4_5f64, 12.3e45f64); +} + +public function testJustBeforeSuffix() { + // normal int + eq(12_0i32, 120i32); + eq(1_2_0i32, 120i32); + + // hex int + eq(0x12_0i32, 0x120i32); + eq(0x1_2_0i32, 0x120i32); + + // normal float + feq(12.3_4f64, 12.34f64); + feq(1_2.34f64, 12.34f64); + feq(1_2.3_4f64, 12.34f64); + + // dot float + feq(.3_4f64, .34f64); + feq(.3_4_5f64, .345f64); + + // science float + feq(1_2e3_4f64, 12e34f64); + feq(1_2.3e4_5f64, 12.3e45f64); + + feq(1_2e-3_4f64, 12e-34f64); + feq(1_2.3e-4_5f64, 12.3e-45f64); + feq(1_2e+3_4f64, 12e+34f64); + feq(1_2.3e+4_5f64, 12.3e+45f64); + + feq(-1_2e-3_4f64, -12e-34f64); + feq(-1_2.3e-4_5f64, -12.3e-45f64); + feq(-1_2e+3_4f64, -12e+34f64); + feq(-1_2.3e+4_5f64, -12.3e+45f64); +}