@@ -54,7 +54,7 @@ module.exports = grammar({
5454 $ . ternary_expression ,
5555 $ . mutation_expression ,
5656 $ . function ,
57- $ . let_binding ,
57+ $ . let_declaration ,
5858 ] ,
5959 // Nested.Module.Path precendence
6060 [
@@ -83,9 +83,10 @@ module.exports = grammar({
8383 [ $ . array , $ . array_pattern ] ,
8484 [ $ . record_field , $ . record_pattern ] ,
8585 [ $ . expression_statement , $ . ternary_expression ] ,
86- [ $ . _type_declaration ] ,
87- [ $ . _let_binding ] ,
88- [ $ . let_binding , $ . ternary_expression ] ,
86+ [ $ . type_declaration ] ,
87+ [ $ . type_binding ] ,
88+ [ $ . let_declaration ] ,
89+ [ $ . let_declaration , $ . ternary_expression ] ,
8990 [ $ . variant_identifier , $ . module_identifier ] ,
9091 [ $ . variant , $ . variant_pattern ] ,
9192 [ $ . variant_declaration , $ . function_type_parameter ] ,
@@ -102,13 +103,15 @@ module.exports = grammar({
102103 [ $ . primary_expression , $ . parameter , $ . _pattern ] ,
103104 [ $ . parameter , $ . _pattern ] ,
104105 [ $ . parameter , $ . parenthesized_pattern ] ,
106+ [ $ . parameter , $ . tuple_item_pattern ] ,
105107 [ $ . variant_declaration ] ,
106108 [ $ . unit , $ . _function_type_parameter_list ] ,
107109 [ $ . functor_parameter , $ . module_primary_expression , $ . module_identifier_path ] ,
108110 [ $ . _reserved_identifier , $ . function ] ,
109111 [ $ . polyvar_type ] ,
110- [ $ . _let_binding , $ . or_pattern ] ,
111- [ $ . exception_pattern , $ . or_pattern ]
112+ [ $ . let_binding , $ . or_pattern ] ,
113+ [ $ . exception_pattern , $ . or_pattern ] ,
114+ [ $ . type_binding , $ . _inline_type ]
112115 ] ,
113116
114117 rules : {
@@ -176,13 +179,13 @@ module.exports = grammar({
176179
177180 declaration : $ => choice (
178181 $ . type_declaration ,
179- $ . let_binding ,
182+ $ . let_declaration ,
180183 $ . module_declaration ,
181184 $ . external_declaration ,
182185 $ . exception_declaration ,
183186 ) ,
184187
185- _module_binding : $ => prec . left ( seq (
188+ module_binding : $ => prec . left ( seq (
186189 field ( 'name' , choice ( $ . module_identifier , $ . type_identifier ) ) ,
187190 optional ( seq (
188191 ':' ,
@@ -191,20 +194,14 @@ module.exports = grammar({
191194 optional ( seq (
192195 '=' ,
193196 field ( 'definition' , $ . _module_definition ) ,
194- optional ( $ . _module_binding_and )
195197 ) ) ,
196198 ) ) ,
197199
198- _module_binding_and : $ => seq (
199- 'and' ,
200- $ . _module_binding
201- ) ,
202-
203200 module_declaration : $ => seq (
204201 'module' ,
205202 optional ( 'rec' ) ,
206203 optional ( 'type' ) ,
207- $ . _module_binding ,
204+ sep1 ( 'and' , $ . module_binding )
208205 ) ,
209206
210207 _module_definition : $ => choice (
@@ -273,31 +270,24 @@ module.exports = grammar({
273270 optional ( 'export' ) ,
274271 'type' ,
275272 optional ( 'rec' ) ,
276- $ . _type_declaration
273+ sep1 (
274+ seq ( repeat ( $ . _newline ) , repeat ( $ . decorator ) , 'and' ) ,
275+ $ . type_binding
276+ )
277277 ) ,
278278
279- _type_declaration : $ => seq (
280- choice ( $ . type_identifier , $ . type_identifier_path ) ,
279+ type_binding : $ => seq (
280+ field ( 'name' , choice ( $ . type_identifier , $ . type_identifier_path ) ) ,
281281 optional ( $ . type_parameters ) ,
282282 optional ( seq (
283- optional ( seq ( '=' , $ . _type ) ) ,
283+ optional ( seq ( '=' , $ . _non_function_inline_type ) ) ,
284284 optional ( seq (
285285 choice ( '=' , '+=' ) ,
286286 optional ( 'private' ) ,
287- $ . _type ,
287+ field ( 'body' , $ . _type ) ,
288288 ) ) ,
289289 repeat ( $ . type_constraint ) ,
290290 ) ) ,
291- optional ( alias ( $ . _type_declaration_and , $ . type_declaration ) )
292- ) ,
293-
294- _type_declaration_and : $ => seq (
295- // New line here not necessary terminates the statement,
296- // show this doubt to the parser
297- repeat ( $ . _newline ) ,
298- repeat ( $ . decorator ) ,
299- 'and' ,
300- $ . _type_declaration
301291 ) ,
302292
303293 type_parameters : $ => seq (
@@ -480,30 +470,33 @@ module.exports = grammar({
480470 ) ,
481471 ) ,
482472
483- let_binding : $ => seq (
473+ let_declaration : $ => seq (
484474 choice ( 'export' , 'let' ) ,
485475 optional ( 'rec' ) ,
486- $ . _let_binding ,
487- ) ,
488-
489- _let_binding : $ => seq (
490- $ . _pattern ,
491- optional ( $ . type_annotation ) ,
492- optional ( seq (
493- '=' ,
494- repeat ( $ . decorator ) ,
495- $ . expression ,
496- optional ( alias ( $ . _let_binding_and , $ . let_binding ) ) ,
497- ) ) ,
476+ sep1 (
477+ seq ( repeat ( $ . _newline ) , repeat ( $ . decorator ) , 'and' ) ,
478+ $ . let_binding
479+ )
498480 ) ,
499481
500- _let_binding_and : $ => seq (
501- // New line here not necessary terminates the statement,
502- // show this doubt to the parser
503- repeat ( $ . _newline ) ,
504- repeat ( $ . decorator ) ,
505- 'and' ,
506- $ . _let_binding ,
482+ let_binding : $ => seq (
483+ field ( 'pattern' , $ . _pattern ) ,
484+ choice (
485+ seq (
486+ $ . type_annotation ,
487+ optional (
488+ seq ( '=' ,
489+ repeat ( $ . decorator ) ,
490+ field ( 'body' , $ . expression )
491+ )
492+ )
493+ ) ,
494+ seq (
495+ '=' ,
496+ repeat ( $ . decorator ) ,
497+ field ( 'body' , $ . expression ) ,
498+ )
499+ )
507500 ) ,
508501
509502 expression_statement : $ => $ . expression ,
@@ -820,7 +813,7 @@ module.exports = grammar({
820813 parameter : $ => seq (
821814 optional ( $ . uncurry ) ,
822815 choice (
823- $ . _pattern ,
816+ seq ( $ . _pattern , optional ( $ . type_annotation ) ) ,
824817 $ . labeled_parameter ,
825818 $ . unit ,
826819 $ . abstract_type
@@ -865,7 +858,6 @@ module.exports = grammar({
865858 $ . range_pattern ,
866859 $ . exception_pattern
867860 ) ,
868- optional ( $ . type_annotation ) ,
869861 optional ( $ . as_aliasing ) ,
870862 ) ) ,
871863
@@ -938,14 +930,15 @@ module.exports = grammar({
938930 '}'
939931 ) ,
940932
933+ tuple_item_pattern : $ => seq (
934+ repeat ( $ . decorator ) ,
935+ $ . _pattern ,
936+ optional ( $ . type_annotation ) ,
937+ ) ,
938+
941939 tuple_pattern : $ => seq (
942940 '(' ,
943- commaSep2t (
944- alias (
945- seq ( repeat ( $ . decorator ) , $ . _pattern ) ,
946- $ . tuple_item_pattern
947- )
948- ) ,
941+ commaSep2t ( $ . tuple_item_pattern ) ,
949942 ')' ,
950943 ) ,
951944
0 commit comments