Skip to content

Commit b422b74

Browse files
authored
Merge pull request #151 from aspeddro/support-lazy
support lazy
2 parents 0e112b3 + 9775141 commit b422b74

File tree

4 files changed

+54
-14
lines changed

4 files changed

+54
-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],
@@ -438,7 +440,7 @@ module.exports = grammar({
438440
),
439441

440442
_let_binding: $ => seq(
441-
$._binding_pattern,
443+
$._pattern,
442444
optional($.type_annotation),
443445
optional(seq(
444446
'=',
@@ -457,16 +459,6 @@ module.exports = grammar({
457459
$._let_binding,
458460
),
459461

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

472464
expression: $ => choice(
@@ -513,6 +505,7 @@ module.exports = grammar({
513505
$.member_expression,
514506
$.module_pack,
515507
$.extension_expression,
508+
$.lazy_expression,
516509
),
517510

518511
parenthesized_expression: $ => seq(
@@ -838,6 +831,7 @@ module.exports = grammar({
838831
$.polyvar_type_pattern,
839832
$.unit,
840833
$.module_pack,
834+
$.lazy_pattern,
841835
$._parenthesized_pattern,
842836
)),
843837
optional($.type_annotation),
@@ -931,8 +925,15 @@ module.exports = grammar({
931925
choice($.value_identifier, $.list_pattern, $.array_pattern),
932926
),
933927

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

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

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

queries/highlights.scm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@
116116
"await"
117117
"with"
118118
"unpack"
119+
"lazy"
119120
] @keyword
120121

121122
[

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)