Skip to content

Commit 86b5fe3

Browse files
committed
include_statement: better support
1 parent 14e7605 commit 86b5fe3

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed

grammar.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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) {
15371540
function path(prefix, final) {
15381541
return choice(final, seq(prefix, '.', final))
15391542
}
1543+
1544+
function parenthesize(rule) {
1545+
return seq('(', rule, ')')
1546+
}

test/corpus/modules.txt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ include (Belt: module type of Belt with module Map.Inner := Belt.Map and module
3232
include module type of {
3333
include T
3434
}
35+
include (
36+
{
37+
let a = Js.log("Hello")
38+
}
39+
)
3540

3641
---
3742

@@ -78,7 +83,15 @@ include module type of {
7883

7984
(include_statement
8085
(module_type_of
81-
(block (include_statement (module_identifier))))))
86+
(block (include_statement (module_identifier)))))
87+
88+
(include_statement
89+
(block
90+
(let_declaration
91+
(let_binding (value_identifier)
92+
(call_expression
93+
(value_identifier_path (module_identifier) (value_identifier))
94+
(arguments (string (string_fragment)))))))))
8295

8396
===========================================
8497
Simple definition

0 commit comments

Comments
 (0)