Skip to content

Commit 2716313

Browse files
authored
Merge pull request rescript-lang#199 from aspeddro/fix-unpack-constraint
support unpack with constrain type
2 parents f07c6f8 + fc5fa4f commit 2716313

File tree

2 files changed

+49
-5
lines changed

2 files changed

+49
-5
lines changed

grammar.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,19 @@ module.exports = grammar({
214214
$.extension_expression,
215215
),
216216

217-
module_unpack: $ => seq('unpack', $.call_arguments),
217+
module_unpack: $ => seq(
218+
'unpack',
219+
'(',
220+
choice(
221+
seq(
222+
choice($.value_identifier, $.value_identifier_path, $.member_expression),
223+
optional($.module_type_annotation)
224+
),
225+
$.call_expression,
226+
$.extension_expression
227+
),
228+
')'
229+
),
218230

219231
functor: $ => seq(
220232
field('parameters', $.functor_parameters),
@@ -1137,7 +1149,7 @@ module.exports = grammar({
11371149
$.block,
11381150
),
11391151

1140-
lazy_expression: $ => seq(
1152+
lazy_expression: $ => seq(
11411153
'lazy',
11421154
$.expression,
11431155
),
@@ -1353,7 +1365,7 @@ module.exports = grammar({
13531365
$._escape_identifier,
13541366
),
13551367

1356-
_escape_identifier: $ => token(seq('\\"', /[^"]+/ , '"')),
1368+
_escape_identifier: $ => token(seq('\\"', /[^"]+/, '"')),
13571369

13581370
module_identifier: $ => /[A-Z][a-zA-Z0-9_']*/,
13591371

@@ -1447,7 +1459,7 @@ module.exports = grammar({
14471459
choice(
14481460
/[a-z_][a-zA-Z0-9_']*/,
14491461
// escape_sequence
1450-
seq('\\"', /[^"]+/ , '"'),
1462+
seq('\\"', /[^"]+/, '"'),
14511463
)
14521464
),
14531465
'`',

test/corpus/modules.txt

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,14 @@ module(
164164
)
165165
module(SomeFunctor(unpack(x)))
166166

167+
module T = unpack(foo: T)
168+
169+
module S = unpack(foo: T with type t = a)
170+
171+
module S = unpack(Mod.read(v))
172+
173+
module S = unpack(%extension(payload))
174+
167175
---
168176

169177
(source_file
@@ -187,7 +195,31 @@ module(SomeFunctor(unpack(x)))
187195
(module_identifier)
188196
(arguments
189197
(module_unpack
190-
(call_arguments (value_identifier))))))))
198+
(value_identifier))))))
199+
(module_declaration
200+
(module_identifier)
201+
(module_unpack
202+
(value_identifier)
203+
(module_type_annotation (module_identifier))))
204+
(module_declaration
205+
(module_identifier)
206+
(module_unpack
207+
(value_identifier)
208+
(module_type_annotation
209+
(module_type_constraint (module_identifier)
210+
(constrain_type (type_identifier) (type_identifier))))))
211+
(module_declaration
212+
(module_identifier)
213+
(module_unpack
214+
(call_expression
215+
(value_identifier_path (module_identifier) (value_identifier))
216+
(arguments (value_identifier)))))
217+
(module_declaration
218+
(module_identifier)
219+
(module_unpack
220+
(extension_expression
221+
(extension_identifier)
222+
(expression_statement (value_identifier))))))
191223

192224

193225
===========================================

0 commit comments

Comments
 (0)