Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ module.exports = grammar({
[$.polyvar_type],
[$.let_binding, $.or_pattern],
[$.exception_pattern, $.or_pattern],
[$.type_binding, $._inline_type]
[$.type_binding, $._inline_type],
[$._module_structure, $.parenthesized_module_expression]
],

rules: {
Expand Down Expand Up @@ -176,7 +177,10 @@ module.exports = grammar({

include_statement: $ => seq(
'include',
$.module_expression,
choice(
$._module_definition,
parenthesize($._module_structure)
)
),

declaration: $ => choice(
Expand Down Expand Up @@ -206,6 +210,11 @@ module.exports = grammar({
sep1('and', $.module_binding)
),

_module_structure: $ => seq(
$._module_definition,
optional($.module_type_annotation),
),

_module_definition: $ => choice(
$.block,
$.module_expression,
Expand Down Expand Up @@ -757,13 +766,7 @@ module.exports = grammar({

module_pack: $ => seq(
'module',
'(',
choice(
$.type_identifier_path,
$._module_definition,
),
optional($.module_type_annotation),
')'
parenthesize(choice($._module_structure, $.type_identifier_path))
),

call_arguments: $ => seq(
Expand Down Expand Up @@ -1537,3 +1540,7 @@ function sep1(delimiter, rule) {
function path(prefix, final) {
return choice(final, seq(prefix, '.', final))
}

function parenthesize(rule) {
return seq('(', rule, ')')
}
15 changes: 14 additions & 1 deletion test/corpus/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ include (Belt: module type of Belt with module Map.Inner := Belt.Map and module
include module type of {
include T
}
include (
{
let a = Js.log("Hello")
}
)

---

Expand Down Expand Up @@ -78,7 +83,15 @@ include module type of {

(include_statement
(module_type_of
(block (include_statement (module_identifier))))))
(block (include_statement (module_identifier)))))

(include_statement
(block
(let_declaration
(let_binding (value_identifier)
(call_expression
(value_identifier_path (module_identifier) (value_identifier))
(arguments (string (string_fragment)))))))))

===========================================
Simple definition
Expand Down