Skip to content

Commit f8d93e4

Browse files
authored
Merge pull request #161 from aspeddro/support-and-rec-module
Support `and` rec module
2 parents 0c18f52 + cbe075b commit f8d93e4

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

grammar.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,7 @@ module.exports = grammar({
177177
$.exception_declaration,
178178
),
179179

180-
module_declaration: $ => seq(
181-
'module',
182-
optional('rec'),
183-
optional('type'),
180+
_module_binding: $ => prec.left(seq(
184181
field('name', choice($.module_identifier, $.type_identifier)),
185182
optional(seq(
186183
':',
@@ -189,7 +186,20 @@ module.exports = grammar({
189186
optional(seq(
190187
'=',
191188
field('definition', $._module_definition),
189+
repeat($._module_binding_and)
192190
)),
191+
)),
192+
193+
_module_binding_and: $ => seq(
194+
'and',
195+
$._module_binding
196+
),
197+
198+
module_declaration: $ => seq(
199+
'module',
200+
optional('rec'),
201+
optional('type'),
202+
$._module_binding,
193203
),
194204

195205
_module_definition: $ => choice(

test/corpus/modules.txt

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,14 +288,33 @@ module rec BYOBReader: {
288288
include Reader
289289
} = BYOBReader
290290

291+
module rec A: T = {
292+
let x = B.x
293+
}
294+
and B: T = {
295+
let x = 1
296+
}
297+
291298
---
292299

293300
(source_file
294301
(module_declaration
295302
(module_identifier)
296303
(block
297304
(include_statement (module_identifier)))
298-
(module_identifier)))
305+
(module_identifier))
306+
307+
(module_declaration
308+
(module_identifier) (module_identifier)
309+
(block
310+
(let_binding
311+
(value_identifier)
312+
(value_identifier_path
313+
(module_identifier) (value_identifier))))
314+
(module_identifier) (module_identifier)
315+
(block
316+
(let_binding
317+
(value_identifier) (number)))))
299318

300319
===========================================
301320
Definition through extension

0 commit comments

Comments
 (0)