Skip to content

Commit 881aae7

Browse files
committed
polish: modules
1 parent 254b8e1 commit 881aae7

File tree

2 files changed

+30
-26
lines changed

2 files changed

+30
-26
lines changed

grammar.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,10 @@ module.exports = grammar({
151151

152152
include_statement: $ => seq(
153153
'include',
154-
choice($.module_expression, seq('(', $.module_expression, ')')),
154+
choice(
155+
$.module_expression,
156+
seq('(', choice($.module_expression, $.functor_parameter), ')')
157+
),
155158
),
156159

157160
declaration: $ => choice(
@@ -200,7 +203,7 @@ module.exports = grammar({
200203
),
201204

202205
functor_parameter: $ => seq(
203-
$.module_identifier,
206+
$.module_identifier_path,
204207
$.module_type_annotation,
205208
),
206209

@@ -710,8 +713,8 @@ module.exports = grammar({
710713
module_pack: $ => seq(
711714
'module',
712715
'(',
713-
choice($.module_expression, $.block),
714-
optional(seq(':', $.module_expression)),
716+
$._module_definition,
717+
optional($.module_type_annotation),
715718
')'
716719
),
717720

@@ -1240,8 +1243,6 @@ module.exports = grammar({
12401243
)),
12411244

12421245
module_type_constraint: $ => seq(
1243-
$.module_expression,
1244-
optional(':'),
12451246
$.module_expression,
12461247
'with',
12471248
sep1('and',

test/corpus/modules.txt

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,12 @@ include module type of {
7777
(module_identifier))))
7878

7979
(include_statement
80-
(module_type_constraint
80+
(functor_parameter
8181
(module_identifier_path (module_identifier))
82-
(module_type_of
83-
(module_identifier_path (module_identifier)))
82+
(module_type_annotation
83+
(module_type_constraint
84+
(module_type_of
85+
(module_identifier_path (module_identifier)))
8486
(constrain_module
8587
(module_identifier_path (module_identifier))
8688
(module_identifier_path
@@ -92,7 +94,7 @@ include module type of {
9294
(module_identifier_path
9395
(module_identifier_path
9496
(module_identifier))
95-
(module_identifier)))))
97+
(module_identifier)))))))
9698

9799
(include_statement
98100
(module_type_of
@@ -201,15 +203,15 @@ module(SomeFunctor(unpack(x)))
201203
(expression_statement
202204
(module_pack
203205
(module_identifier_path (module_identifier))
204-
(module_identifier_path (module_identifier))))
206+
(module_type_annotation (module_identifier_path (module_identifier)))))
205207
(expression_statement
206208
(module_pack
207209
(block
208210
(type_declaration (type_identifier))
209211
(let_binding
210212
(value_identifier)
211213
(string (string_fragment))))
212-
(module_identifier_path (module_identifier))))
214+
(module_type_annotation (module_identifier_path (module_identifier)))))
213215
(expression_statement
214216
(module_pack
215217
(functor_use
@@ -236,10 +238,10 @@ module MyFunctor = (X: {type t}, Y: {type t}): {type tx; type ty} => {
236238
definition: (functor
237239
parameters: (functor_parameters
238240
(functor_parameter
239-
(module_identifier)
241+
(module_identifier_path (module_identifier))
240242
(module_type_annotation (block (type_declaration (type_identifier)))))
241243
(functor_parameter
242-
(module_identifier)
244+
(module_identifier_path (module_identifier))
243245
(module_type_annotation (block (type_declaration (type_identifier))))))
244246
return_module_type: (module_type_annotation
245247
(block (type_declaration (type_identifier)) (type_declaration (type_identifier))))
@@ -262,7 +264,7 @@ module Make: (Content: StaticContent) => {
262264
(module_identifier)
263265
(functor
264266
(functor_parameters
265-
(functor_parameter (module_identifier) (module_type_annotation (module_identifier_path (module_identifier)))))
267+
(functor_parameter (module_identifier_path (module_identifier)) (module_type_annotation (module_identifier_path (module_identifier)))))
266268
(block
267269
(let_binding
268270
(value_identifier)
@@ -494,14 +496,15 @@ module(M: T with type t = a and type t = b)
494496
(source_file
495497
(expression_statement
496498
(module_pack
497-
(module_type_constraint
498-
(module_identifier_path
499-
(module_identifier))
500-
(module_identifier_path
501-
(module_identifier))
502-
(constrain_type
503-
(type_identifier)
504-
(type_identifier))
505-
(constrain_type
506-
(type_identifier)
507-
(type_identifier))))))
499+
(module_identifier_path
500+
(module_identifier))
501+
(module_type_annotation
502+
(module_type_constraint
503+
(module_identifier_path
504+
(module_identifier))
505+
(constrain_type
506+
(type_identifier)
507+
(type_identifier))
508+
(constrain_type
509+
(type_identifier)
510+
(type_identifier)))))))

0 commit comments

Comments
 (0)