@@ -113,7 +113,8 @@ module.exports = grammar({
113113 [ $ . polyvar_type ] ,
114114 [ $ . let_binding , $ . or_pattern ] ,
115115 [ $ . exception_pattern , $ . or_pattern ] ,
116- [ $ . type_binding , $ . _inline_type ]
116+ [ $ . type_binding , $ . _inline_type ] ,
117+ [ $ . _module_structure , $ . parenthesized_module_expression ]
117118 ] ,
118119
119120 rules : {
@@ -176,7 +177,10 @@ module.exports = grammar({
176177
177178 include_statement : $ => seq (
178179 'include' ,
179- $ . module_expression ,
180+ choice (
181+ $ . _module_definition ,
182+ parenthesize ( $ . _module_structure )
183+ )
180184 ) ,
181185
182186 declaration : $ => choice (
@@ -206,6 +210,11 @@ module.exports = grammar({
206210 sep1 ( 'and' , $ . module_binding )
207211 ) ,
208212
213+ _module_structure : $ => seq (
214+ $ . _module_definition ,
215+ optional ( $ . module_type_annotation ) ,
216+ ) ,
217+
209218 _module_definition : $ => choice (
210219 $ . block ,
211220 $ . module_expression ,
@@ -754,13 +763,7 @@ module.exports = grammar({
754763
755764 module_pack : $ => seq (
756765 'module' ,
757- '(' ,
758- choice (
759- $ . type_identifier_path ,
760- $ . _module_definition ,
761- ) ,
762- optional ( $ . module_type_annotation ) ,
763- ')'
766+ parenthesize ( choice ( $ . _module_structure , $ . type_identifier_path ) )
764767 ) ,
765768
766769 call_arguments : $ => seq (
@@ -1534,3 +1537,7 @@ function sep1(delimiter, rule) {
15341537function path ( prefix , final ) {
15351538 return choice ( final , seq ( prefix , '.' , final ) )
15361539}
1540+
1541+ function parenthesize ( rule ) {
1542+ return seq ( '(' , rule , ')' )
1543+ }
0 commit comments