Skip to content

Commit 2b778c8

Browse files
committed
fix: update Java grammar to fix parsing of lambda switch rule results and keyword statement labels
1 parent e30853c commit 2b778c8

8 files changed

Lines changed: 50 additions & 5 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
"mitata": "^1.0.34",
7171
"mocha": "^11.7.5",
7272
"prettier": "^3.8.1",
73-
"tree-sitter-java-orchard": "0.5.6",
73+
"tree-sitter-java-orchard": "0.5.8",
7474
"tsdown": "^0.22.0",
7575
"typescript": "^6.0.3",
7676
"typescript-eslint": "^8.57.1"

test/unit-test/expressions/_input.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ public void printIf() {
9797
}
9898
}
9999

100+
void labeledStatement() {
101+
record: if (true) {}
102+
}
103+
100104
public void printSwitch() {
101105
switch(myValue == 42 || myValue == 42 && myValue == 42 && myValue == 42 || myValue == 42 && myValue == 42) {
102106

test/unit-test/expressions/_output.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ public void printIf() {
107107
}
108108
}
109109

110+
void labeledStatement() {
111+
record: if (true) {
112+
}
113+
}
114+
110115
public void printSwitch() {
111116
switch (
112117
myValue == 42 ||

test/unit-test/lambda/arrow-parens-always/_input.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,15 @@ void lambdaInParentheses() {
341341
void lambdaWithAssignmentBody() {
342342
a -> b = c;
343343
}
344+
345+
void switchRulesWithLambdaResults() {
346+
Function<Integer, Integer> f = switch (o) {
347+
case false -> a -> a + 1;
348+
case B -> a -> a + 2;
349+
case Boolean b when b -> a -> a + 3;
350+
default -> c -> c + 4;
351+
};
352+
}
344353
}
345354

346355
class T {

test/unit-test/lambda/arrow-parens-always/_output.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,15 @@ void lambdaInParentheses() {
575575
void lambdaWithAssignmentBody() {
576576
(a) -> b = c;
577577
}
578+
579+
void switchRulesWithLambdaResults() {
580+
Function<Integer, Integer> f = switch (o) {
581+
case false -> (a) -> a + 1;
582+
case B -> (a) -> a + 2;
583+
case Boolean b when b -> (a) -> a + 3;
584+
default -> (c) -> c + 4;
585+
};
586+
}
578587
}
579588

580589
class T {

test/unit-test/lambda/arrow-parens-avoid/_input.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,15 @@ void lambdaInParentheses() {
341341
void lambdaWithAssignmentBody() {
342342
a -> b = c;
343343
}
344+
345+
void switchRulesWithLambdaResults() {
346+
Function<Integer, Integer> f = switch (o) {
347+
case false -> a -> a + 1;
348+
case B -> a -> a + 2;
349+
case Boolean b when b -> a -> a + 3;
350+
default -> c -> c + 4;
351+
};
352+
}
344353
}
345354

346355
class T {

test/unit-test/lambda/arrow-parens-avoid/_output.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,15 @@ void lambdaInParentheses() {
575575
void lambdaWithAssignmentBody() {
576576
a -> b = c;
577577
}
578+
579+
void switchRulesWithLambdaResults() {
580+
Function<Integer, Integer> f = switch (o) {
581+
case false -> a -> a + 1;
582+
case B -> a -> a + 2;
583+
case Boolean b when b -> a -> a + 3;
584+
default -> c -> c + 4;
585+
};
586+
}
578587
}
579588

580589
class T {

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4751,10 +4751,10 @@ tree-kill@^1.2.2:
47514751
resolved "https://registry.yarnpkg.com/tree-kill/-/tree-kill-1.2.2.tgz#4ca09a9092c88b73a7cdc5e8a01b507b0790a0cc"
47524752
integrity sha512-L0Orpi8qGpRG//Nd+H90vFB+3iHnue1zSSGmNOOCh1GLJ7rUKVwV2HvijphGQS2UmhUZewS9VgvxYIdgr+fG1A==
47534753

4754-
tree-sitter-java-orchard@0.5.6:
4755-
version "0.5.6"
4756-
resolved "https://registry.yarnpkg.com/tree-sitter-java-orchard/-/tree-sitter-java-orchard-0.5.6.tgz#9bcac73eee928ef8fbf4c2c8c57de2d0627711b3"
4757-
integrity sha512-nn6D9bE73ltYTtLudi3fxJ4/lFQCcRyXb9qaVRGOcv5Xi+y0xQNZ/z4PJaVki+KqaiIcR70tViZztLhnSvouYA==
4754+
tree-sitter-java-orchard@0.5.8:
4755+
version "0.5.8"
4756+
resolved "https://registry.yarnpkg.com/tree-sitter-java-orchard/-/tree-sitter-java-orchard-0.5.8.tgz#c3e2f02ce4c1aabe2fa66cd21c91ffc0620b7b56"
4757+
integrity sha512-vT7d1MbTL2ceVkfqZZRr0AVfNC2b2Vl/bReql4kJ4cMfbT3K/RS4FlK05bjaW/Q6gAa7FEHFP9HODIQDLXr1Zg==
47584758
dependencies:
47594759
node-addon-api "^8.3.1"
47604760
node-gyp-build "^4.8.4"

0 commit comments

Comments
 (0)