Skip to content

Commit dc9024a

Browse files
committed
Add more repositories to validate parsing and fix a few more cases.
This adds the following repositories: * Apache Flink * Apache Log4j2 * Apache Cassandra The grammar has been updated to address the following cases: * Reserved identifiers used as a lambda parameter * Enum declared inside an annotation * Conflict between switch as a statement or an expression when used in the following pattern: ```java switch(foo) { ... } ++bar; ```
1 parent 65746a4 commit dc9024a

File tree

8 files changed

+35284
-28426
lines changed

8 files changed

+35284
-28426
lines changed

grammar.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const PREC = {
44
// https://introcs.cs.princeton.edu/java/11precedence/
55
COMMENT: 0, // // /* */
66
ASSIGN: 1, // = += -= *= /= %= &= ^= |= <<= >>= >>>=
7-
SWITCH_EXP: 1, // always prefer to parse switch as expression over statement
87
DECL: 2,
98
ELEMENT_VAL: 2,
109
TERNARY: 3, // ?:
@@ -66,6 +65,7 @@ module.exports = grammar({
6665
[$._unannotated_type, $.scoped_type_identifier],
6766
[$._unannotated_type, $.generic_type],
6867
[$.generic_type, $.primary_expression],
68+
[$.expression, $.statement],
6969
// Only conflicts in switch expressions
7070
[$.lambda_expression, $.primary_expression],
7171
],
@@ -174,7 +174,7 @@ module.exports = grammar({
174174
$.primary_expression,
175175
$.unary_expression,
176176
$.cast_expression,
177-
prec(PREC.SWITCH_EXP, $.switch_expression),
177+
$.switch_expression,
178178
),
179179

180180
cast_expression: $ => prec(PREC.CAST, seq(
@@ -232,7 +232,7 @@ module.exports = grammar({
232232

233233
lambda_expression: $ => seq(
234234
field('parameters', choice(
235-
$.identifier, $.formal_parameters, $.inferred_parameters
235+
$.identifier, $.formal_parameters, $.inferred_parameters, $._reserved_identifier
236236
)),
237237
'->',
238238
field('body', choice($.expression, $.block))
@@ -920,6 +920,7 @@ module.exports = grammar({
920920
$.constant_declaration,
921921
$.class_declaration,
922922
$.interface_declaration,
923+
$.enum_declaration,
923924
$.annotation_type_declaration
924925
)),
925926
'}'

script/known-failures.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
examples/flink/flink-quickstart/flink-quickstart-java/src/main/resources/archetype-resources/src/main/java/DataStreamJob.java
2+
examples/flink/flink-walkthroughs/flink-walkthrough-datastream-java/src/main/resources/archetype-resources/src/main/java/FraudDetectionJob.java
3+
examples/flink/flink-walkthroughs/flink-walkthrough-datastream-java/src/main/resources/archetype-resources/src/main/java/FraudDetector.java

script/parse-examples

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ function clone_repo {
2828
clone_repo elastic elasticsearch 4d62640bf116af7e825d89c7319a39c3f2f325b4
2929
clone_repo google guava v31.1
3030
clone_repo ReactiveX RxJava v3.1.5
31+
clone_repo apache flink release-1.15.1
32+
clone_repo apache logging-log4j2 rel/2.17.2
33+
clone_repo apache cassandra cassandra-4.0.5
3134

3235
known_failures="$(cat script/known-failures.txt)"
3336

src/grammar.json

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,12 +1194,8 @@
11941194
"name": "cast_expression"
11951195
},
11961196
{
1197-
"type": "PREC",
1198-
"value": 1,
1199-
"content": {
1200-
"type": "SYMBOL",
1201-
"name": "switch_expression"
1202-
}
1197+
"type": "SYMBOL",
1198+
"name": "switch_expression"
12031199
}
12041200
]
12051201
},
@@ -2041,6 +2037,10 @@
20412037
{
20422038
"type": "SYMBOL",
20432039
"name": "inferred_parameters"
2040+
},
2041+
{
2042+
"type": "SYMBOL",
2043+
"name": "_reserved_identifier"
20442044
}
20452045
]
20462046
}
@@ -5814,6 +5814,10 @@
58145814
"type": "SYMBOL",
58155815
"name": "interface_declaration"
58165816
},
5817+
{
5818+
"type": "SYMBOL",
5819+
"name": "enum_declaration"
5820+
},
58175821
{
58185822
"type": "SYMBOL",
58195823
"name": "annotation_type_declaration"
@@ -7017,6 +7021,10 @@
70177021
"generic_type",
70187022
"primary_expression"
70197023
],
7024+
[
7025+
"expression",
7026+
"statement"
7027+
],
70207028
[
70217029
"lambda_expression",
70227030
"primary_expression"

src/node-types.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,10 @@
483483
"type": "constant_declaration",
484484
"named": true
485485
},
486+
{
487+
"type": "enum_declaration",
488+
"named": true
489+
},
486490
{
487491
"type": "interface_declaration",
488492
"named": true

0 commit comments

Comments
 (0)