@@ -45,7 +45,6 @@ module.exports = grammar({
4545
4646 conflicts : $ => [
4747 [ $ . _simple_name , $ . generic_name ] ,
48- [ $ . _simple_name , $ . constructor_declaration ] ,
4948 [ $ . _simple_name , $ . type_parameter ] ,
5049
5150 [ $ . tuple_element , $ . type_pattern ] ,
@@ -90,6 +89,13 @@ module.exports = grammar({
9089 [ $ . parameter , $ . tuple_element ] ,
9190
9291 [ $ . event_declaration , $ . variable_declarator ] ,
92+
93+ [ $ . base_list ] ,
94+ [ $ . using_directive , $ . modifier ] ,
95+ [ $ . using_directive ] ,
96+
97+
98+ [ $ . _constructor_declaration_initializer , $ . _simple_name ] ,
9399 ] ,
94100
95101 externals : $ => [
@@ -183,8 +189,7 @@ module.exports = grammar({
183189 $ . type ,
184190 ) ,
185191 seq (
186- optional ( 'static' ) ,
187- optional ( 'unsafe' ) ,
192+ repeat ( choice ( 'static' , 'unsafe' ) ) ,
188193 $ . _name ,
189194 ) ,
190195 ) ,
@@ -257,30 +262,34 @@ module.exports = grammar({
257262 ) ,
258263
259264 class_declaration : $ => seq (
265+ $ . _class_declaration_initializer ,
266+ $ . _optional_semi ,
267+ ) ,
268+
269+ _class_declaration_initializer : $ => seq (
260270 repeat ( $ . attribute_list ) ,
261271 repeat ( $ . modifier ) ,
262272 'class' ,
263273 field ( 'name' , $ . identifier ) ,
264- optional ( $ . type_parameter_list ) ,
265- optional ( $ . parameter_list ) ,
266- optional ( $ . base_list ) ,
274+ repeat ( choice ( $ . type_parameter_list , $ . parameter_list , $ . base_list ) ) ,
267275 repeat ( $ . type_parameter_constraints_clause ) ,
268276 field ( 'body' , $ . declaration_list ) ,
269- $ . _optional_semi ,
270277 ) ,
271278
272279 struct_declaration : $ => seq (
280+ $ . _struct_declaration_initializer ,
281+ field ( 'body' , $ . declaration_list ) ,
282+ $ . _optional_semi ,
283+ ) ,
284+
285+ _struct_declaration_initializer : $ => seq (
273286 repeat ( $ . attribute_list ) ,
274287 repeat ( $ . modifier ) ,
275288 optional ( 'ref' ) ,
276289 'struct' ,
277290 field ( 'name' , $ . identifier ) ,
278- optional ( $ . type_parameter_list ) ,
279- optional ( $ . parameter_list ) ,
280- optional ( $ . base_list ) ,
291+ repeat ( choice ( $ . type_parameter_list , $ . parameter_list , $ . base_list ) ) ,
281292 repeat ( $ . type_parameter_constraints_clause ) ,
282- field ( 'body' , $ . declaration_list ) ,
283- $ . _optional_semi ,
284293 ) ,
285294
286295 enum_declaration : $ => seq (
@@ -310,41 +319,52 @@ module.exports = grammar({
310319 ) ,
311320
312321 interface_declaration : $ => seq (
322+ $ . _interface_declaration_initializer ,
323+ field ( 'body' , $ . declaration_list ) ,
324+ $ . _optional_semi ,
325+ ) ,
326+
327+ _interface_declaration_initializer : $ => seq (
313328 repeat ( $ . attribute_list ) ,
314329 repeat ( $ . modifier ) ,
315330 'interface' ,
316331 field ( 'name' , $ . identifier ) ,
317332 field ( 'type_parameters' , optional ( $ . type_parameter_list ) ) ,
318333 optional ( $ . base_list ) ,
319334 repeat ( $ . type_parameter_constraints_clause ) ,
320- field ( 'body' , $ . declaration_list ) ,
321- $ . _optional_semi ,
322335 ) ,
323336
324337 delegate_declaration : $ => seq (
338+ $ . _delegate_declaration_initializer ,
339+ repeat ( $ . type_parameter_constraints_clause ) ,
340+ ';' ,
341+ ) ,
342+
343+ _delegate_declaration_initializer : $ => seq (
325344 repeat ( $ . attribute_list ) ,
326345 repeat ( $ . modifier ) ,
327346 'delegate' ,
328347 field ( 'type' , $ . type ) ,
329348 field ( 'name' , $ . identifier ) ,
330349 field ( 'type_parameters' , optional ( $ . type_parameter_list ) ) ,
331350 field ( 'parameters' , $ . parameter_list ) ,
332- repeat ( $ . type_parameter_constraints_clause ) ,
333- ';' ,
334351 ) ,
335352
336353 record_declaration : $ => seq (
354+ $ . _record_declaration_initializer ,
355+ choice ( field ( 'body' , $ . declaration_list ) , ';' ) ,
356+ $ . _optional_semi ,
357+ ) ,
358+
359+ _record_declaration_initializer : $ => seq (
337360 repeat ( $ . attribute_list ) ,
338361 repeat ( $ . modifier ) ,
339362 'record' ,
340363 optional ( choice ( 'class' , 'struct' ) ) ,
341364 field ( 'name' , $ . identifier ) ,
342- optional ( $ . type_parameter_list ) ,
343- optional ( $ . parameter_list ) ,
365+ repeat ( choice ( $ . type_parameter_list , $ . parameter_list ) ) ,
344366 optional ( alias ( $ . record_base , $ . base_list ) ) ,
345367 repeat ( $ . type_parameter_constraints_clause ) ,
346- choice ( field ( 'body' , $ . declaration_list ) , ';' ) ,
347- $ . _optional_semi ,
348368 ) ,
349369
350370 record_base : $ => choice (
@@ -445,9 +465,11 @@ module.exports = grammar({
445465 'implicit' ,
446466 'explicit' ,
447467 ) ,
448- optional ( $ . explicit_interface_specifier ) ,
449- 'operator' ,
450- optional ( 'checked' ) ,
468+ repeat1 ( choice (
469+ $ . explicit_interface_specifier ,
470+ 'operator' ,
471+ 'checked' ,
472+ ) ) ,
451473 field ( 'type' , $ . type ) ,
452474 field ( 'parameters' , $ . parameter_list ) ,
453475 $ . _function_body ,
@@ -489,12 +511,16 @@ module.exports = grammar({
489511 ) ,
490512
491513 constructor_declaration : $ => seq (
514+ $ . _constructor_declaration_initializer ,
515+ $ . _function_body ,
516+ ) ,
517+
518+ _constructor_declaration_initializer : $ => seq (
492519 repeat ( $ . attribute_list ) ,
493520 repeat ( $ . modifier ) ,
494521 field ( 'name' , $ . identifier ) ,
495522 field ( 'parameters' , $ . parameter_list ) ,
496523 optional ( $ . constructor_initializer ) ,
497- $ . _function_body ,
498524 ) ,
499525
500526 destructor_declaration : $ => seq (
@@ -923,6 +949,11 @@ module.exports = grammar({
923949
924950 for_statement : $ => seq (
925951 'for' ,
952+ $ . _for_statement_conditions ,
953+ field ( 'body' , $ . statement ) ,
954+ ) ,
955+
956+ _for_statement_conditions : $ => seq (
926957 '(' ,
927958 field ( 'initializer' , optional (
928959 choice ( $ . variable_declaration , commaSep1 ( $ . expression ) ) ,
@@ -932,7 +963,6 @@ module.exports = grammar({
932963 ';' ,
933964 field ( 'update' , optional ( commaSep1 ( $ . expression ) ) ) ,
934965 ')' ,
935- field ( 'body' , $ . statement ) ,
936966 ) ,
937967
938968 return_statement : $ => seq ( 'return' , optional ( $ . expression ) , ';' ) ,
@@ -989,8 +1019,7 @@ module.exports = grammar({
9891019
9901020 catch_clause : $ => seq (
9911021 'catch' ,
992- optional ( $ . catch_declaration ) ,
993- optional ( $ . catch_filter_clause ) ,
1022+ repeat ( choice ( $ . catch_declaration , $ . catch_filter_clause ) ) ,
9941023 field ( 'body' , $ . block ) ,
9951024 ) ,
9961025
@@ -1020,6 +1049,11 @@ module.exports = grammar({
10201049 ) ,
10211050
10221051 foreach_statement : $ => seq (
1052+ $ . _foreach_statement_initializer ,
1053+ field ( 'body' , $ . statement ) ,
1054+ ) ,
1055+
1056+ _foreach_statement_initializer : $ => seq (
10231057 optional ( 'await' ) ,
10241058 'foreach' ,
10251059 '(' ,
@@ -1033,7 +1067,6 @@ module.exports = grammar({
10331067 'in' ,
10341068 field ( 'right' , $ . expression ) ,
10351069 ')' ,
1036- field ( 'body' , $ . statement ) ,
10371070 ) ,
10381071
10391072 goto_statement : $ => seq (
@@ -1078,14 +1111,18 @@ module.exports = grammar({
10781111 ) ,
10791112
10801113 local_function_statement : $ => seq (
1114+ $ . _local_function_declaration ,
1115+ repeat ( $ . type_parameter_constraints_clause ) ,
1116+ $ . _function_body ,
1117+ ) ,
1118+
1119+ _local_function_declaration : $ => seq (
10811120 repeat ( $ . attribute_list ) ,
10821121 repeat ( $ . modifier ) ,
10831122 field ( 'type' , $ . type ) ,
10841123 field ( 'name' , $ . identifier ) ,
10851124 field ( 'type_parameters' , optional ( $ . type_parameter_list ) ) ,
10861125 field ( 'parameters' , $ . parameter_list ) ,
1087- repeat ( $ . type_parameter_constraints_clause ) ,
1088- $ . _function_body ,
10891126 ) ,
10901127
10911128 pattern : $ => choice (
@@ -1327,10 +1364,9 @@ module.exports = grammar({
13271364 ) ) ,
13281365 ) ,
13291366
1330- postfix_unary_expression : $ => prec ( PREC . POSTFIX , choice (
1331- seq ( $ . expression , '++' ) ,
1332- seq ( $ . expression , '--' ) ,
1333- seq ( $ . expression , '!' ) ,
1367+ postfix_unary_expression : $ => prec ( PREC . POSTFIX , seq (
1368+ $ . expression ,
1369+ choice ( '++' , '--' , '!' ) ,
13341370 ) ) ,
13351371
13361372 prefix_unary_expression : $ => prec ( PREC . UNARY , seq (
@@ -1467,11 +1503,15 @@ module.exports = grammar({
14671503 switch_expression : $ => prec ( PREC . SWITCH , seq (
14681504 $ . expression ,
14691505 'switch' ,
1506+ $ . _switch_expression_body ,
1507+ ) ) ,
1508+ _switch_expression_body : $ => seq (
14701509 '{' ,
14711510 commaSep ( $ . switch_expression_arm ) ,
14721511 optional ( ',' ) ,
14731512 '}' ,
1474- ) ) ,
1513+ ) ,
1514+
14751515
14761516 switch_expression_arm : $ => seq (
14771517 $ . pattern ,
@@ -1577,13 +1617,18 @@ module.exports = grammar({
15771617 _parenthesized_lvalue_expression : $ => seq ( '(' , $ . lvalue_expression , ')' ) ,
15781618
15791619 lambda_expression : $ => prec ( - 1 , seq (
1620+ $ . _lambda_expression_init ,
1621+ '=>' ,
1622+ field ( 'body' , choice ( $ . block , $ . expression ) ) ,
1623+ ) ) ,
1624+
1625+ _lambda_expression_init : $ => prec ( - 1 , seq (
15801626 repeat ( $ . attribute_list ) ,
15811627 repeat ( prec ( - 1 , alias ( choice ( 'static' , 'async' ) , $ . modifier ) ) ) ,
15821628 optional ( field ( 'type' , $ . type ) ) ,
15831629 field ( 'parameters' , $ . _lambda_parameters ) ,
1584- '=>' ,
1585- field ( 'body' , choice ( $ . block , $ . expression ) ) ,
1586- ) ) ,
1630+ ) ,
1631+ ) ,
15871632
15881633 _lambda_parameters : $ => prec ( - 1 , choice (
15891634 $ . parameter_list ,
@@ -1661,10 +1706,13 @@ module.exports = grammar({
16611706 with_expression : $ => prec . left ( PREC . WITH , seq (
16621707 $ . expression ,
16631708 'with' ,
1709+ $ . _with_body ,
1710+ ) ) ,
1711+ _with_body : $ => seq (
16641712 '{' ,
16651713 commaSep ( $ . with_initializer ) ,
16661714 '}' ,
1667- ) ) ,
1715+ ) ,
16681716
16691717 with_initializer : $ => seq ( $ . identifier , '=' , $ . expression ) ,
16701718
0 commit comments