Skip to content

Commit 1ba755b

Browse files
authored
Merge pull request #206 from aspeddro/fix-include
Fix include_statement
2 parents 3fcb35a + 86b5fe3 commit 1ba755b

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,
@@ -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) {
15341537
function path(prefix, final) {
15351538
return choice(final, seq(prefix, '.', final))
15361539
}
1540+
1541+
function parenthesize(rule) {
1542+
return seq('(', rule, ')')
1543+
}

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)