Skip to content

Commit 630e76a

Browse files
committed
add more cases
1 parent 881aae7 commit 630e76a

File tree

2 files changed

+68
-19
lines changed

2 files changed

+68
-19
lines changed

grammar.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ module.exports = grammar({
211211
':',
212212
choice(
213213
$.module_expression,
214+
seq('(', $.module_expression, ')'),
214215
$.block,
215216
)
216217
),
@@ -1242,14 +1243,23 @@ module.exports = grammar({
12421243
choice($.module_expression, $.block)
12431244
)),
12441245

1245-
module_type_constraint: $ => seq(
1246-
$.module_expression,
1246+
_module_type_constraint: $ => seq(
12471247
'with',
1248-
sep1('and',
1248+
sep1(choice('and', 'with'),
12491249
choice($.constrain_module, $.constrain_type)
12501250
),
12511251
),
12521252

1253+
module_type_constraint: $ => prec.left(choice(
1254+
seq($.module_identifier_path, $._module_type_constraint),
1255+
seq(
1256+
'(',
1257+
$.module_identifier_path, $._module_type_constraint,
1258+
')',
1259+
$._module_type_constraint
1260+
)
1261+
)),
1262+
12531263
constrain_module: $ => seq(
12541264
'module',
12551265
$.module_identifier_path,

test/corpus/modules.txt

Lines changed: 55 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -80,21 +80,21 @@ include module type of {
8080
(functor_parameter
8181
(module_identifier_path (module_identifier))
8282
(module_type_annotation
83+
(module_type_of
8384
(module_type_constraint
84-
(module_type_of
85-
(module_identifier_path (module_identifier)))
86-
(constrain_module
8785
(module_identifier_path (module_identifier))
88-
(module_identifier_path
86+
(constrain_module
87+
(module_identifier_path (module_identifier))
8988
(module_identifier_path
90-
(module_identifier))
91-
(module_identifier)))
92-
(constrain_module
93-
(module_identifier_path (module_identifier))
94-
(module_identifier_path
89+
(module_identifier_path
90+
(module_identifier))
91+
(module_identifier)))
92+
(constrain_module
93+
(module_identifier_path (module_identifier))
9594
(module_identifier_path
96-
(module_identifier))
97-
(module_identifier)))))))
95+
(module_identifier_path
96+
(module_identifier))
97+
(module_identifier))))))))
9898

9999
(include_statement
100100
(module_type_of
@@ -491,20 +491,59 @@ Module Constraints
491491

492492
module(M: T with type t = a and type t = b)
493493

494+
module M = (): (T with type t = int) => {}
495+
496+
module M = (Na: N, Nb: N): (
497+
(S with type t = x) with type a = b
498+
) => {}
499+
494500
---
495501

496502
(source_file
497503
(expression_statement
498504
(module_pack
499-
(module_identifier_path
500-
(module_identifier))
505+
(module_identifier_path (module_identifier))
501506
(module_type_annotation
502507
(module_type_constraint
503-
(module_identifier_path
504-
(module_identifier))
508+
(module_identifier_path (module_identifier))
509+
(constrain_type
510+
(type_identifier)
511+
(type_identifier))
512+
(constrain_type
513+
(type_identifier)
514+
(type_identifier))))))
515+
516+
(module_declaration
517+
(module_identifier)
518+
(functor
519+
(functor_parameters)
520+
(module_type_annotation
521+
(module_type_constraint
522+
(module_identifier_path (module_identifier))
523+
(constrain_type
524+
(type_identifier)
525+
(type_identifier))))
526+
(block)))
527+
528+
(module_declaration
529+
(module_identifier)
530+
(functor
531+
(functor_parameters
532+
(functor_parameter
533+
(module_identifier_path (module_identifier))
534+
(module_type_annotation
535+
(module_identifier_path (module_identifier))))
536+
(functor_parameter
537+
(module_identifier_path (module_identifier))
538+
(module_type_annotation
539+
(module_identifier_path (module_identifier)))))
540+
(module_type_annotation
541+
(module_type_constraint
542+
(module_identifier_path (module_identifier))
505543
(constrain_type
506544
(type_identifier)
507545
(type_identifier))
508546
(constrain_type
509547
(type_identifier)
510-
(type_identifier)))))))
548+
(type_identifier))))
549+
(block))))

0 commit comments

Comments
 (0)