@@ -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 ,
@@ -757,13 +766,7 @@ module.exports = grammar({
757766
758767 module_pack : $ => seq (
759768 'module' ,
760- '(' ,
761- choice (
762- $ . type_identifier_path ,
763- $ . _module_definition ,
764- ) ,
765- optional ( $ . module_type_annotation ) ,
766- ')'
769+ parenthesize ( choice ( $ . _module_structure , $ . type_identifier_path ) )
767770 ) ,
768771
769772 call_arguments : $ => seq (
@@ -1537,3 +1540,7 @@ function sep1(delimiter, rule) {
15371540function path ( prefix , final ) {
15381541 return choice ( final , seq ( prefix , '.' , final ) )
15391542}
1543+
1544+ function parenthesize ( rule ) {
1545+ return seq ( '(' , rule , ')' )
1546+ }
0 commit comments