@@ -24,15 +24,18 @@ module.exports = grammar({
2424 $ . primary_expression ,
2525 $ . _type ,
2626 $ . module_expression ,
27+ $ . module_primary_expression ,
2728 ] ,
2829
2930 precedences : $ => [
31+ // + - Operators -> precendence
3032 [
3133 'unary_not' ,
3234 'member' ,
3335 'call' ,
3436 $ . spread_element ,
3537 $ . await_expression ,
38+ $ . pipe_expression ,
3639 'binary_times' ,
3740 'binary_pow' ,
3841 'binary_plus' ,
@@ -48,14 +51,19 @@ module.exports = grammar({
4851 $ . function ,
4952 $ . let_binding ,
5053 ] ,
54+ // Nested.Module.Path precendence
55+ [
56+ $ . module_primary_expression ,
57+ $ . value_identifier_path ,
58+ $ . nested_variant_identifier ,
59+ $ . module_identifier_path ,
60+ ] ,
5161 [ $ . _jsx_attribute_value , $ . pipe_expression ] ,
5262 [ $ . function_type_parameters , $ . function_type ] ,
53- [ $ . module_identifier_path , $ . module_type_of ] ,
5463 ] ,
5564
5665 conflicts : $ => [
5766 [ $ . unit , $ . formal_parameters ] ,
58- [ $ . pipe_expression , $ . expression ] ,
5967 [ $ . primary_expression , $ . _pattern ] ,
6068 [ $ . primary_expression , $ . record_pattern ] ,
6169 [ $ . primary_expression , $ . spread_pattern ] ,
@@ -64,7 +72,6 @@ module.exports = grammar({
6472 [ $ . tuple_pattern , $ . parameter ] ,
6573 [ $ . primary_expression , $ . parameter ] ,
6674 [ $ . primary_expression , $ . record_field ] ,
67- [ $ . module_identifier_path , $ . module_expression ] ,
6875 [ $ . tuple_type , $ . function_type_parameter ] ,
6976 [ $ . list , $ . list_pattern ] ,
7077 [ $ . array , $ . array_pattern ] ,
@@ -74,10 +81,9 @@ module.exports = grammar({
7481 [ $ . _let_binding ] ,
7582 [ $ . let_binding , $ . ternary_expression ] ,
7683 [ $ . variant_identifier , $ . module_identifier ] ,
77- [ $ . variant ] ,
7884 [ $ . variant , $ . variant_pattern ] ,
7985 [ $ . variant_declaration , $ . function_type_parameter ] ,
80- [ $ . polyvar ] ,
86+ [ $ . variant_arguments , $ . _variant_pattern_parameters ] ,
8187 [ $ . polyvar , $ . polyvar_pattern ] ,
8288 [ $ . _pattern ] ,
8389 [ $ . _record_element , $ . jsx_expression ] ,
@@ -93,7 +99,7 @@ module.exports = grammar({
9399 [ $ . parameter , $ . _parenthesized_pattern ] ,
94100 [ $ . _switch_value_pattern , $ . _parenthesized_pattern ] ,
95101 [ $ . variant_declaration ] ,
96- [ $ . unit , $ . _function_type_parameter_list ]
102+ [ $ . unit , $ . _function_type_parameter_list ] ,
97103 ] ,
98104
99105 rules : {
@@ -205,7 +211,7 @@ module.exports = grammar({
205211 ) ,
206212
207213 functor_parameter : $ => seq (
208- $ . module_identifier_path ,
214+ $ . module_identifier ,
209215 $ . module_type_annotation ,
210216 ) ,
211217
@@ -516,7 +522,7 @@ module.exports = grammar({
516522 ) ,
517523
518524 value_identifier_path : $ => seq (
519- $ . module_identifier_path ,
525+ $ . module_primary_expression ,
520526 '.' ,
521527 $ . value_identifier ,
522528 ) ,
@@ -863,7 +869,7 @@ module.exports = grammar({
863869
864870 _variant_pattern_parameters : $ => seq (
865871 '(' ,
866- commaSep1t ( $ . _variant_pattern_parameter ) ,
872+ commaSept ( $ . _variant_pattern_parameter ) ,
867873 ')' ,
868874 ) ,
869875
@@ -1152,13 +1158,13 @@ module.exports = grammar({
11521158 ')' ,
11531159 ) ,
11541160
1155- variant : $ => prec . dynamic ( - 1 , seq (
1161+ variant : $ => prec . right ( seq (
11561162 choice ( $ . variant_identifier , $ . nested_variant_identifier ) ,
11571163 optional ( alias ( $ . variant_arguments , $ . arguments ) ) ,
11581164 ) ) ,
11591165
11601166 nested_variant_identifier : $ => seq (
1161- $ . module_identifier_path ,
1167+ $ . module_primary_expression ,
11621168 '.' ,
11631169 $ . variant_identifier
11641170 ) ,
@@ -1172,10 +1178,10 @@ module.exports = grammar({
11721178 ')' ,
11731179 ) ,
11741180
1175- polyvar : $ => seq (
1181+ polyvar : $ => prec . right ( seq (
11761182 $ . polyvar_identifier ,
11771183 optional ( alias ( $ . variant_arguments , $ . arguments ) ) ,
1178- ) ,
1184+ ) ) ,
11791185
11801186 _type_identifier : $ =>
11811187 choice (
@@ -1185,22 +1191,27 @@ module.exports = grammar({
11851191 ) ,
11861192
11871193 type_identifier_path : $ => seq (
1188- $ . module_identifier_path ,
1194+ $ . module_primary_expression ,
11891195 '.' ,
11901196 $ . type_identifier
11911197 ) ,
11921198
11931199 module_expression : $ => choice (
1194- $ . module_identifier_path ,
1200+ $ . module_primary_expression ,
11951201 $ . type_identifier_path ,
11961202 $ . module_type_of ,
1197- $ . functor_use ,
11981203 $ . module_type_constraint ,
1204+ ) ,
1205+
1206+ module_primary_expression : $ => choice (
1207+ $ . module_identifier ,
1208+ $ . module_identifier_path ,
1209+ $ . functor_use ,
11991210 $ . module_unpack ,
12001211 ) ,
12011212
12021213 module_identifier_path : $ => path (
1203- $ . module_identifier_path ,
1214+ $ . module_primary_expression ,
12041215 $ . module_identifier ,
12051216 ) ,
12061217
@@ -1211,28 +1222,28 @@ module.exports = grammar({
12111222 choice ( $ . module_expression , $ . block )
12121223 ) ) ,
12131224
1214- _module_type_constraint : $ => seq (
1225+ _module_type_constraint_with : $ => prec . right ( seq (
12151226 'with' ,
12161227 sep1 ( choice ( 'and' , 'with' ) ,
12171228 choice ( $ . constrain_module , $ . constrain_type )
12181229 ) ,
1219- ) ,
1230+ ) ) ,
12201231
12211232 module_type_constraint : $ => prec . left ( choice (
1222- seq ( $ . module_identifier_path , $ . _module_type_constraint ) ,
1233+ seq ( $ . module_expression , $ . _module_type_constraint_with ) ,
12231234 seq (
12241235 '(' ,
1225- $ . module_identifier_path , $ . _module_type_constraint ,
1236+ $ . module_expression , $ . _module_type_constraint_with ,
12261237 ')' ,
1227- $ . _module_type_constraint
1238+ $ . _module_type_constraint_with
12281239 )
12291240 ) ) ,
12301241
12311242 constrain_module : $ => seq (
12321243 'module' ,
1233- $ . module_identifier_path ,
1244+ $ . module_identifier ,
12341245 choice ( '=' , ':=' ) ,
1235- $ . module_identifier_path ,
1246+ $ . module_primary_expression ,
12361247 ) ,
12371248
12381249 constrain_type : $ => seq (
@@ -1243,7 +1254,7 @@ module.exports = grammar({
12431254 ) ,
12441255
12451256 functor_use : $ => seq (
1246- $ . module_identifier_path ,
1257+ $ . module_primary_expression ,
12471258 alias ( $ . functor_arguments , $ . arguments ) ,
12481259 ) ,
12491260
0 commit comments