Skip to content

Commit 56dd030

Browse files
committed
support lazy
Close #149
1 parent 030c543 commit 56dd030

File tree

3 files changed

+53
-14
lines changed

3 files changed

+53
-14
lines changed

grammar.js

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ module.exports = grammar({
4040
$.spread_element,
4141
$.await_expression,
4242
$.pipe_expression,
43+
$.lazy_expression,
4344
'binary_times',
4445
'binary_pow',
4546
'binary_plus',
@@ -72,6 +73,7 @@ module.exports = grammar({
7273
[$.primary_expression, $.record_pattern],
7374
[$.primary_expression, $.spread_pattern],
7475
[$.primary_expression, $._literal_pattern],
76+
[$.primary_expression, $.lazy_pattern],
7577
[$.primary_expression, $._jsx_child],
7678
[$.tuple_pattern, $.parameter],
7779
[$.primary_expression, $.parameter],
@@ -437,7 +439,7 @@ module.exports = grammar({
437439
),
438440

439441
_let_binding: $ => seq(
440-
$._binding_pattern,
442+
$._pattern,
441443
optional($.type_annotation),
442444
optional(seq(
443445
'=',
@@ -456,16 +458,6 @@ module.exports = grammar({
456458
$._let_binding,
457459
),
458460

459-
_binding_pattern: $ => choice(
460-
$.value_identifier,
461-
$.tuple_pattern,
462-
$.record_pattern,
463-
$.array_pattern,
464-
$.list_pattern,
465-
$.module_unpack_pattern,
466-
$.unit
467-
),
468-
469461
expression_statement: $ => $.expression,
470462

471463
expression: $ => choice(
@@ -512,6 +504,7 @@ module.exports = grammar({
512504
$.member_expression,
513505
$.module_pack,
514506
$.extension_expression,
507+
$.lazy_expression,
515508
),
516509

517510
parenthesized_expression: $ => seq(
@@ -837,6 +830,7 @@ module.exports = grammar({
837830
$.polyvar_type_pattern,
838831
$.unit,
839832
$.module_pack,
833+
$.lazy_pattern,
840834
$._parenthesized_pattern,
841835
)),
842836
optional($.type_annotation),
@@ -930,8 +924,15 @@ module.exports = grammar({
930924
choice($.value_identifier, $.list_pattern, $.array_pattern),
931925
),
932926

933-
module_unpack_pattern: $ => seq(
934-
'module', '(', $.module_identifier, ')',
927+
lazy_pattern: $ => seq(
928+
'lazy',
929+
choice(
930+
$.value_identifier,
931+
$._literal_pattern,
932+
$._destructuring_pattern,
933+
$.polyvar_type_pattern,
934+
$._parenthesized_pattern,
935+
)
935936
),
936937

937938
_jsx_element: $ => choice($.jsx_element, $.jsx_self_closing_element),
@@ -1092,6 +1093,11 @@ module.exports = grammar({
10921093
$.block,
10931094
),
10941095

1096+
lazy_expression: $ => seq(
1097+
'lazy',
1098+
$.expression,
1099+
),
1100+
10951101
binary_expression: $ => choice(
10961102
...[
10971103
['&&', 'binary_and'],

test/corpus/expressions.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,3 +1408,22 @@ let f = ({name, _} as foo: T.t) => {}
14081408
(module_identifier)
14091409
(type_identifier))))))
14101410
body: (block))))
1411+
1412+
===========================================
1413+
Lazy Expression
1414+
===========================================
1415+
1416+
lazy { 1 }
1417+
lazy call()
1418+
1419+
---
1420+
1421+
(source_file
1422+
(expression_statement
1423+
(lazy_expression
1424+
(block
1425+
(expression_statement (number)))))
1426+
(expression_statement
1427+
(lazy_expression
1428+
(call_expression
1429+
(value_identifier) (arguments)))))

test/corpus/let_bindings.txt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,5 +328,19 @@ let module(Bar) = foo
328328

329329
(source_file
330330
(let_binding
331-
(module_unpack_pattern (module_identifier))
331+
(module_pack (module_identifier))
332332
(value_identifier)))
333+
334+
===========================================
335+
Lazy Values
336+
===========================================
337+
338+
let lazy x = lazy(1)
339+
340+
---
341+
342+
(source_file
343+
(let_binding
344+
(lazy_pattern (value_identifier))
345+
(lazy_expression
346+
(parenthesized_expression (number)))))

0 commit comments

Comments
 (0)