Skip to content

Commit 388720a

Browse files
committed
refactor: remove condition rule
1 parent 2aae502 commit 388720a

File tree

3 files changed

+32
-25
lines changed

3 files changed

+32
-25
lines changed

grammar.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -369,8 +369,6 @@ module.exports = grammar({
369369

370370
parenthesized_expression: $ => seq('(', $.expression, ')'),
371371

372-
condition: $ => seq('(', $.expression, ')'),
373-
374372
class_literal: $ => prec.dynamic(PREC.CLASS_LITERAL, seq($._unannotated_type, '.', 'class')),
375373

376374
object_creation_expression: $ => choice(
@@ -648,14 +646,14 @@ module.exports = grammar({
648646

649647
if_statement: $ => prec.right(seq(
650648
'if',
651-
field('condition', $.condition),
649+
field('condition', $.parenthesized_expression),
652650
field('consequence', $.statement),
653651
optional(seq('else', field('alternative', $.statement)))
654652
)),
655653

656654
while_statement: $ => seq(
657655
'while',
658-
field('condition', $.condition),
656+
field('condition', $.parenthesized_expression),
659657
field('body', $.statement)
660658
),
661659

test/corpus/declarations.txt

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -685,14 +685,20 @@ public class A {
685685
(modifiers)
686686
(identifier)
687687
(formal_parameters
688-
(receiver_parameter (type_identifier) (this)))
688+
(receiver_parameter
689+
(type_identifier)
690+
(this)))
689691
(constructor_body))
690692
(constructor_declaration
691693
(modifiers)
692694
(identifier)
693695
(formal_parameters
694-
(receiver_parameter (type_identifier) (this))
695-
(formal_parameter (type_identifier) (identifier)))
696+
(receiver_parameter
697+
(type_identifier)
698+
(this))
699+
(formal_parameter
700+
(type_identifier)
701+
(identifier)))
696702
(constructor_body)))))
697703

698704
================================================================================
@@ -967,7 +973,7 @@ record Person(int age) {
967973
(identifier)
968974
(block
969975
(if_statement
970-
(condition
976+
(parenthesized_expression
971977
(binary_expression
972978
(identifier)
973979
(decimal_integer_literal)))
@@ -1185,14 +1191,17 @@ public class A {
11851191
(object_creation_expression
11861192
(type_arguments
11871193
(annotated_type
1188-
(marker_annotation (identifier))
1194+
(marker_annotation
1195+
(identifier))
11891196
(type_identifier)))
1190-
(marker_annotation (identifier))
1197+
(marker_annotation
1198+
(identifier))
11911199
(generic_type
11921200
(type_identifier)
11931201
(type_arguments
11941202
(annotated_type
1195-
(marker_annotation (identifier))
1203+
(marker_annotation
1204+
(identifier))
11961205
(type_identifier))))
11971206
(argument_list
11981207
(null_literal)))))))))

test/corpus/expressions.txt

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ if (x)
170170

171171
(program
172172
(if_statement
173-
condition: (condition
173+
condition: (parenthesized_expression
174174
(identifier))
175175
consequence: (expression_statement
176176
(identifier))))
@@ -186,7 +186,7 @@ if ((x))
186186

187187
(program
188188
(if_statement
189-
condition: (condition
189+
condition: (parenthesized_expression
190190
(parenthesized_expression
191191
(identifier)))
192192
consequence: (expression_statement
@@ -204,7 +204,7 @@ if (x) {
204204

205205
(program
206206
(if_statement
207-
condition: (condition
207+
condition: (parenthesized_expression
208208
(identifier))
209209
consequence: (block
210210
(expression_statement
@@ -221,7 +221,7 @@ if (x = 3)
221221

222222
(program
223223
(if_statement
224-
condition: (condition
224+
condition: (parenthesized_expression
225225
(assignment_expression
226226
left: (identifier)
227227
right: (decimal_integer_literal)))
@@ -244,7 +244,7 @@ if (x = 3) {
244244

245245
(program
246246
(if_statement
247-
condition: (condition
247+
condition: (parenthesized_expression
248248
(assignment_expression
249249
left: (identifier)
250250
right: (decimal_integer_literal)))
@@ -273,10 +273,10 @@ if (a)
273273

274274
(program
275275
(if_statement
276-
(condition
276+
(parenthesized_expression
277277
(identifier))
278278
(if_statement
279-
(condition
279+
(parenthesized_expression
280280
(identifier))
281281
(expression_statement
282282
(method_invocation
@@ -428,7 +428,7 @@ class WhileDemo {
428428
name: (identifier)
429429
value: (decimal_integer_literal)))
430430
(while_statement
431-
condition: (condition
431+
condition: (parenthesized_expression
432432
(binary_expression
433433
left: (identifier)
434434
right: (decimal_integer_literal)))
@@ -1187,7 +1187,7 @@ public class Patterns {
11871187
(argument_list
11881188
(identifier)))))))
11891189
(if_statement
1190-
(condition
1190+
(parenthesized_expression
11911191
(instanceof_expression
11921192
(identifier)
11931193
(record_pattern
@@ -1198,7 +1198,7 @@ public class Patterns {
11981198
(identifier))))))
11991199
(block))
12001200
(if_statement
1201-
(condition
1201+
(parenthesized_expression
12021202
(instanceof_expression
12031203
(identifier)
12041204
(record_pattern
@@ -1209,7 +1209,7 @@ public class Patterns {
12091209
(identifier))))))
12101210
(block))
12111211
(if_statement
1212-
(condition
1212+
(parenthesized_expression
12131213
(instanceof_expression
12141214
(identifier)
12151215
(record_pattern
@@ -1229,7 +1229,7 @@ public class Patterns {
12291229
(identifier))))))
12301230
(block))
12311231
(if_statement
1232-
(condition
1232+
(parenthesized_expression
12331233
(instanceof_expression
12341234
(identifier)
12351235
(record_pattern
@@ -1319,7 +1319,7 @@ public class Switches {
13191319
(expression_statement
13201320
(decimal_integer_literal)))))
13211321
(if_statement
1322-
(condition
1322+
(parenthesized_expression
13231323
(instanceof_expression
13241324
(identifier)
13251325
(record_pattern
@@ -1906,7 +1906,7 @@ for (int i = 0, _ = sideEffect(); i < 10; i++) { }
19061906
(enhanced_for_statement
19071907
(type_identifier)
19081908
(underscore_pattern)
1909-
(identifier)
1909+
(identifier)
19101910
(block))
19111911
(for_statement
19121912
(local_variable_declaration

0 commit comments

Comments
 (0)