@@ -81,6 +81,9 @@ module.exports = grammar({
8181 [ $ . destructuring_literal , $ . _expression ] ,
8282 [ $ . namespace_scope_expression , $ . generic_type ] ,
8383 [ $ . _expression , $ . generic_type ] ,
84+ [ $ . optional_type , $ . closure_function_type ] ,
85+ [ $ . _simple_type , $ . generic_function_declaration ] ,
86+ [ $ . _expression , $ . match_default_binding_expression ] ,
8487 ] ,
8588
8689 rules : {
@@ -122,7 +125,6 @@ module.exports = grammar({
122125 $ . function_declaration ,
123126 $ . comptime_function_declaration ,
124127 $ . generic_function_declaration ,
125- $ . closure_function ,
126128 ) ,
127129
128130 logical_not_expression : $ => prec . left ( PREC . not , seq (
@@ -153,10 +155,13 @@ module.exports = grammar({
153155 $ . none_expression ,
154156 $ . update_expression ,
155157 $ . match_expression ,
158+ $ . match_default_binding_expression ,
156159 $ . pointer_expression ,
157160 $ . parenthesized_expression ,
158161 $ . try_expression ,
159162 $ . array_expression ,
163+ $ . reflect_expression ,
164+ $ . closure_function_expression ,
160165 ) ,
161166
162167 parenthesized_expression : $ => prec . left ( 1 , seq (
@@ -298,14 +303,18 @@ module.exports = grammar({
298303 ) ,
299304 ) ,
300305
301- field_expression : $ => prec ( PREC . field , seq (
306+ field_expression : $ => prec ( PREC . field , prec . left ( seq (
302307 field ( 'value' , choice ( $ . this_reference , $ . _expression ) ) ,
303308 '.' ,
304- field ( 'field' , choice (
305- $ . _field_identifier ,
306- $ . integer_literal ,
307- ) )
308- ) ) ,
309+ field ( 'field' , seq (
310+ optional ( '[' ) ,
311+ choice (
312+ $ . _field_identifier ,
313+ $ . integer_literal ,
314+ ) ,
315+ optional ( ']' ) ,
316+ ) ) ,
317+ ) ) ) ,
309318
310319 namespace_call_expression : $ => prec ( PREC . call , prec . left ( seq (
311320 field ( 'namespace' , alias ( $ . identifier , $ . scoped_identifier ) ) ,
@@ -345,6 +354,11 @@ module.exports = grammar({
345354 ) ,
346355 ) ) ,
347356
357+ reflect_expression : $ => seq (
358+ 'reflect' ,
359+ $ . identifier ,
360+ ) ,
361+
348362 pointer_expression : $ => prec . left ( 1 , seq (
349363 field ( 'operator' , choice ( '&' , '*' ) ) ,
350364 optional ( choice ( 'raw' , $ . mutable_specifier ) ) ,
@@ -370,15 +384,15 @@ module.exports = grammar({
370384
371385 arguments : $ => prec . left ( seq (
372386 '(' ,
373- optional ( repeat ( seq ( choice ( $ . argument , $ . closure_function ) , optional ( ',' ) ) ) ) ,
387+ optional ( repeat ( seq ( choice ( $ . argument ) , optional ( ',' ) ) ) ) ,
374388 ')'
375389 ) ) ,
376390
377391 argument : $ => prec . left ( choice (
378392 seq (
379393 field ( 'label' , $ . _pattern ) ,
380394 ':' ,
381- field ( 'value' , choice ( $ . _expression , $ . closure_function ) ) ,
395+ field ( 'value' , $ . _expression ) ,
382396 ) ,
383397 seq ( field ( 'type' , choice ( $ . identifier ) ) , terminator ) ,
384398 field ( "value" , seq ( $ . _expression ) ) ,
@@ -400,6 +414,8 @@ module.exports = grammar({
400414 $ . reference_type ,
401415 $ . closure_function_type ,
402416 $ . tuple_type ,
417+ $ . optional_type ,
418+ $ . pointer_type ,
403419 ) ,
404420
405421 namespace_scope_type : $ => token ( repeat1 ( seq ( identifier , '::' ) ) ) ,
@@ -446,11 +462,11 @@ module.exports = grammar({
446462 field ( 'pattern' , $ . _pattern ) ,
447463 optional ( seq (
448464 ':' ,
449- field ( 'type' , choice ( $ . _type , $ . optional_type ) ) ,
465+ field ( 'type' , $ . _type ) ,
450466 ) ) ,
451467 optional ( seq (
452468 '=' ,
453- field ( 'value' , choice ( $ . _expression , $ . closure_function ) ) ,
469+ field ( 'value' , $ . _expression ) ,
454470 ) ) ,
455471 ) ) ,
456472
@@ -460,7 +476,7 @@ module.exports = grammar({
460476 optional ( seq (
461477 ':' ,
462478 optional ( $ . weak_specifier ) ,
463- field ( 'type' , choice ( $ . _type , $ . optional_type ) ) ,
479+ field ( 'type' , $ . _type ) ,
464480 ) ) ,
465481 optional ( seq (
466482 '=' ,
@@ -500,7 +516,7 @@ module.exports = grammar({
500516 enum_field_declaration : $ => seq (
501517 field ( 'name' , $ . _field_identifier ) ,
502518 ':' ,
503- field ( 'type' , choice ( $ . _type , $ . optional_type ) ) ,
519+ field ( 'type' , $ . _type ) ,
504520 optional ( seq (
505521 '=' ,
506522 field ( 'value' , $ . _expression )
@@ -555,7 +571,7 @@ module.exports = grammar({
555571 optional ( $ . visibility_specifier ) ,
556572 field ( 'name' , $ . _field_identifier ) ,
557573 ':' ,
558- field ( 'type' , choice ( $ . _type , $ . optional_type ) ) ,
574+ field ( 'type' , $ . _type ) ,
559575 optional ( seq (
560576 '=' ,
561577 field ( 'value' , $ . _expression )
@@ -676,18 +692,27 @@ module.exports = grammar({
676692 match_arm : $ => seq (
677693 field ( 'pattern' , seq ( $ . match_pattern ) ) ,
678694 '=>' ,
679- field ( 'value' , choice ( $ . _expression , $ . block , $ . closure_function ) )
695+ field ( 'value' , choice ( $ . _expression , $ . block ) )
696+ ) ,
697+
698+ match_default_binding_expression : $ => seq (
699+ $ . identifier ,
700+ 'default' ,
701+ '(' ,
702+ optional ( $ . mutable_specifier ) ,
703+ field ( 'binding' , $ . identifier ) ,
704+ '=' ,
705+ field ( 'value' , $ . _literal ) ,
706+ ')' ,
680707 ) ,
681708
682709 last_match_arm : $ => seq (
683710 field ( 'pattern' , choice ( $ . match_else , $ . match_else_binding , $ . match_pattern ) ) ,
684711 '=>' ,
685- field ( 'value' , choice ( $ . _expression , $ . block , $ . closure_function ) )
712+ field ( 'value' , choice ( $ . _expression , $ . block ) )
686713 ) ,
687714
688- match_pattern : $ => seq (
689- choice ( $ . _expression ) ,
690- ) ,
715+ match_pattern : $ => seq ( $ . _expression ) ,
691716
692717 match_else : $ => 'else' ,
693718 match_else_binding : $ => seq ( 'else' , '(' , $ . identifier , ')' ) ,
@@ -795,7 +820,7 @@ module.exports = grammar({
795820
796821 tuple_type : $ => seq (
797822 '(' ,
798- sepBy ( ',' , seq ( choice ( $ . _type , $ . optional_type ) , optional ( ',' ) ) ) ,
823+ sepBy ( ',' , seq ( $ . _type , optional ( ',' ) ) ) ,
799824 ')'
800825 ) ,
801826
@@ -864,16 +889,17 @@ module.exports = grammar({
864889 field ( 'name' , choice ( $ . identifier , $ . trait_requirement ) ) ,
865890 field ( 'parameters' , $ . parameters ) ,
866891 optional ( field ( 'throws' , $ . throws_specifier ) ) ,
867- optional ( seq ( '->' , field ( 'return_type' , choice ( $ . _type , $ . optional_type , $ . pointer_type ) ) ) ) ,
892+ optional ( seq ( '->' , field ( 'return_type' , $ . _type ) ) ) ,
868893 optional ( field ( 'body' , choice ( $ . return_expression , $ . block ) ) ) ,
869894 ) ) ,
870895
871896 comptime_function_declaration : $ => prec . right ( seq (
872897 choice ( 'comptime' ) ,
873- field ( 'name' , choice ( $ . identifier , $ . trait_requirement ) ) ,
898+ field ( 'name' , choice ( $ . identifier , $ . generic_type ) ) ,
874899 field ( 'parameters' , $ . parameters ) ,
875900 optional ( field ( 'throws' , $ . throws_specifier ) ) ,
876- optional ( seq ( '->' , field ( 'return_type' , choice ( $ . _type , $ . optional_type , $ . pointer_type ) ) ) ) ,
901+ optional ( seq ( '->' , field ( 'return_type' , $ . _type ) ) ) ,
902+
877903 optional ( field ( 'body' , choice ( $ . return_expression , $ . block ) ) ) ,
878904 ) ) ,
879905
@@ -896,7 +922,7 @@ module.exports = grammar({
896922 field ( 'name' , $ . generic_type ) ,
897923 field ( 'parameters' , $ . parameters ) ,
898924 optional ( field ( 'throws' , $ . throws_specifier ) ) ,
899- optional ( seq ( '->' , field ( 'return_type' , choice ( alias ( $ . _type_identifier , $ . generic_type_identifier ) , $ . generic_type , $ . optional_type ) ) ) ) ,
925+ optional ( seq ( '->' , field ( 'return_type' , choice ( alias ( $ . _type_identifier , $ . generic_type_identifier ) , $ . generic_type , $ . _type ) ) ) ) ,
900926 optional ( field ( 'body' , choice ( $ . return_expression , $ . block ) ) ) ,
901927 ) ) ,
902928
@@ -933,13 +959,7 @@ module.exports = grammar({
933959 $ . _pattern ,
934960 ) ) ,
935961 ':' ,
936- field ( 'type' , seq (
937- choice (
938- $ . _type ,
939- $ . pointer_type ,
940- $ . optional_type ,
941- ) ,
942- ) ) ,
962+ field ( 'type' , $ . _type ) ,
943963 optional ( seq (
944964 '=' ,
945965 field ( 'value' , $ . _expression )
@@ -956,21 +976,25 @@ module.exports = grammar({
956976
957977 _closure_capture_reference : $ => seq (
958978 '[' ,
959- alias ( choice ( $ . identifier , $ . pointer_expression ) , $ . capture_reference ) ,
979+ choice (
980+ alias ( choice ( $ . identifier , $ . pointer_expression ) , $ . capture_reference ) ,
981+ sepBy1 ( ',' , seq ( $ . comptime_specifier , $ . identifier ) ) ,
982+ ) ,
960983 ']' ,
961984 ) ,
962985
963- closure_function : $ => seq (
986+ closure_function_expression : $ => seq (
964987 optional ( choice ( $ . restricted_specifier , $ . visibility_specifier ) ) ,
965988 'fn' ,
966989 optional ( $ . _closure_capture_reference ) ,
967990 field ( 'parameters' , $ . parameters ) ,
968991 optional ( field ( 'throws' , $ . throws_specifier ) ) ,
969- optional ( seq ( '->' , field ( 'return_type' , choice ( $ . _type , $ . optional_type ) ) ) ) ,
992+ optional ( seq ( '->' , field ( 'return_type' , $ . _type ) ) ) ,
970993 field ( 'body' , choice ( $ . return_expression , $ . block ) ) ,
971994 ) ,
972995
973996 anonymous_specifier : $ => 'anon' ,
997+ comptime_specifier : $ => 'comptime' ,
974998
975999 block : $ => prec ( 1 , seq (
9761000 '{' ,
0 commit comments