@@ -153,7 +153,10 @@ module.exports = grammar({
153153
154154 include_statement : $ => seq (
155155 'include' ,
156- choice ( $ . module_expression , seq ( '(' , $ . module_expression , ')' ) ) ,
156+ choice (
157+ $ . module_expression ,
158+ seq ( '(' , choice ( $ . module_expression , $ . functor_parameter ) , ')' )
159+ ) ,
157160 ) ,
158161
159162 declaration : $ => choice (
@@ -202,14 +205,15 @@ module.exports = grammar({
202205 ) ,
203206
204207 functor_parameter : $ => seq (
205- $ . module_identifier ,
208+ $ . module_identifier_path ,
206209 $ . module_type_annotation ,
207210 ) ,
208211
209212 module_type_annotation : $ => seq (
210213 ':' ,
211214 choice (
212215 $ . module_expression ,
216+ seq ( '(' , $ . module_expression , ')' ) ,
213217 $ . block ,
214218 )
215219 ) ,
@@ -291,18 +295,8 @@ module.exports = grammar({
291295 $ . object_type ,
292296 $ . generic_type ,
293297 $ . unit_type ,
298+ $ . module_pack ,
294299 $ . unit ,
295- $ . module_pack_type ,
296- ) ,
297-
298- module_pack_type : $ => seq (
299- 'module' ,
300- '(' ,
301- choice ( $ . module_identifier , $ . _type_identifier ) ,
302- optional (
303- seq ( 'with' , sep1 ( 'and' , seq ( 'type' , $ . _type_identifier , '=' , $ . _type_identifier ) ) )
304- ) ,
305- ')'
306300 ) ,
307301
308302 tuple_type : $ => prec . dynamic ( - 1 , seq (
@@ -509,7 +503,7 @@ module.exports = grammar({
509503 $ . pipe_expression ,
510504 $ . subscript_expression ,
511505 $ . member_expression ,
512- $ . module_pack_expression ,
506+ $ . module_pack ,
513507 $ . extension_expression ,
514508 ) ,
515509
@@ -522,7 +516,8 @@ module.exports = grammar({
522516 ) ,
523517
524518 value_identifier_path : $ => seq (
525- repeat1 ( seq ( $ . module_identifier , '.' ) ) ,
519+ $ . module_identifier_path ,
520+ '.' ,
526521 $ . value_identifier ,
527522 ) ,
528523
@@ -736,11 +731,11 @@ module.exports = grammar({
736731 ) ,
737732 ) ) ,
738733
739- module_pack_expression : $ => seq (
734+ module_pack : $ => seq (
740735 'module' ,
741736 '(' ,
742- choice ( $ . module_expression , $ . block ) ,
743- optional ( seq ( ':' , $ . module_expression ) ) ,
737+ $ . _module_definition ,
738+ optional ( $ . module_type_annotation ) ,
744739 ')'
745740 ) ,
746741
@@ -831,7 +826,8 @@ module.exports = grammar({
831826 $ . _destructuring_pattern ,
832827 $ . polyvar_type_pattern ,
833828 $ . unit ,
834- $ . _parenthesized_pattern
829+ $ . module_pack ,
830+ $ . _parenthesized_pattern ,
835831 ) ) ,
836832 optional ( $ . type_annotation ) ,
837833 optional ( $ . as_aliasing ) ,
@@ -1214,7 +1210,8 @@ module.exports = grammar({
12141210 ) ) ,
12151211
12161212 nested_variant_identifier : $ => seq (
1217- repeat1 ( seq ( $ . module_identifier , '.' ) ) ,
1213+ $ . module_identifier_path ,
1214+ '.' ,
12181215 $ . variant_identifier
12191216 ) ,
12201217
@@ -1240,54 +1237,65 @@ module.exports = grammar({
12401237 ) ,
12411238
12421239 type_identifier_path : $ => seq (
1243- repeat1 ( seq ( $ . module_identifier , '.' ) ) ,
1240+ $ . module_identifier_path ,
1241+ '.' ,
12441242 $ . type_identifier
12451243 ) ,
12461244
12471245 module_expression : $ => choice (
1248- $ . module_identifier ,
12491246 $ . module_identifier_path ,
1247+ $ . type_identifier_path ,
12501248 $ . module_type_of ,
12511249 $ . functor_use ,
12521250 $ . module_type_constraint ,
12531251 $ . module_unpack ,
12541252 ) ,
12551253
1256- module_identifier_path : $ => prec . left ( seq (
1257- $ . module_expression ,
1258- '.' ,
1254+ module_identifier_path : $ => path (
1255+ $ . module_identifier_path ,
12591256 $ . module_identifier ,
1260- ) ) ,
1257+ ) ,
12611258
1262- module_type_of : $ => prec . dynamic ( - 1 , seq (
1259+ module_type_of : $ => prec . left ( seq (
12631260 'module' ,
12641261 'type' ,
12651262 'of' ,
1266- choice ( $ . module_expression , $ . block ) ,
1263+ choice ( $ . module_expression , $ . block )
12671264 ) ) ,
12681265
1269- module_type_constraint : $ => seq (
1270- '(' ,
1271- choice ( $ . module_identifier , $ . module_identifier_path ) ,
1272- ':' ,
1273- $ . module_type_of ,
1266+ _module_type_constraint : $ => seq (
12741267 'with' ,
1275- sep1 ( 'and' ,
1276- seq (
1277- 'module' ,
1278- $ . module_expression ,
1279- choice ( '=' , ':=' ) ,
1280- $ . module_expression
1281- )
1268+ sep1 ( choice ( 'and' , 'with' ) ,
1269+ choice ( $ . constrain_module , $ . constrain_type )
12821270 ) ,
1283- ')'
1271+ ) ,
1272+
1273+ module_type_constraint : $ => prec . left ( choice (
1274+ seq ( $ . module_identifier_path , $ . _module_type_constraint ) ,
1275+ seq (
1276+ '(' ,
1277+ $ . module_identifier_path , $ . _module_type_constraint ,
1278+ ')' ,
1279+ $ . _module_type_constraint
1280+ )
1281+ ) ) ,
1282+
1283+ constrain_module : $ => seq (
1284+ 'module' ,
1285+ $ . module_identifier_path ,
1286+ choice ( '=' , ':=' ) ,
1287+ $ . module_identifier_path ,
1288+ ) ,
1289+
1290+ constrain_type : $ => seq (
1291+ 'type' ,
1292+ $ . _type ,
1293+ choice ( '=' , ':=' ) ,
1294+ $ . _type ,
12841295 ) ,
12851296
12861297 functor_use : $ => seq (
1287- choice (
1288- $ . module_identifier ,
1289- $ . module_identifier_path ,
1290- ) ,
1298+ $ . module_identifier_path ,
12911299 alias ( $ . functor_arguments , $ . arguments ) ,
12921300 ) ,
12931301
@@ -1486,3 +1494,7 @@ function commaSept(rule) {
14861494function sep1 ( delimiter , rule ) {
14871495 return seq ( rule , repeat ( seq ( delimiter , rule ) ) )
14881496}
1497+
1498+ function path ( prefix , final ) {
1499+ return choice ( final , seq ( prefix , '.' , final ) )
1500+ }
0 commit comments