Skip to content

Commit

Permalink
support lazy
Browse files Browse the repository at this point in the history
  • Loading branch information
aspeddro committed Nov 8, 2022
1 parent 030c543 commit 56dd030
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 14 deletions.
32 changes: 19 additions & 13 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ module.exports = grammar({
$.spread_element,
$.await_expression,
$.pipe_expression,
$.lazy_expression,
'binary_times',
'binary_pow',
'binary_plus',
Expand Down Expand Up @@ -72,6 +73,7 @@ module.exports = grammar({
[$.primary_expression, $.record_pattern],
[$.primary_expression, $.spread_pattern],
[$.primary_expression, $._literal_pattern],
[$.primary_expression, $.lazy_pattern],
[$.primary_expression, $._jsx_child],
[$.tuple_pattern, $.parameter],
[$.primary_expression, $.parameter],
Expand Down Expand Up @@ -437,7 +439,7 @@ module.exports = grammar({
),

_let_binding: $ => seq(
$._binding_pattern,
$._pattern,
optional($.type_annotation),
optional(seq(
'=',
Expand All @@ -456,16 +458,6 @@ module.exports = grammar({
$._let_binding,
),

_binding_pattern: $ => choice(
$.value_identifier,
$.tuple_pattern,
$.record_pattern,
$.array_pattern,
$.list_pattern,
$.module_unpack_pattern,
$.unit
),

expression_statement: $ => $.expression,

expression: $ => choice(
Expand Down Expand Up @@ -512,6 +504,7 @@ module.exports = grammar({
$.member_expression,
$.module_pack,
$.extension_expression,
$.lazy_expression,
),

parenthesized_expression: $ => seq(
Expand Down Expand Up @@ -837,6 +830,7 @@ module.exports = grammar({
$.polyvar_type_pattern,
$.unit,
$.module_pack,
$.lazy_pattern,
$._parenthesized_pattern,
)),
optional($.type_annotation),
Expand Down Expand Up @@ -930,8 +924,15 @@ module.exports = grammar({
choice($.value_identifier, $.list_pattern, $.array_pattern),
),

module_unpack_pattern: $ => seq(
'module', '(', $.module_identifier, ')',
lazy_pattern: $ => seq(
'lazy',
choice(
$.value_identifier,
$._literal_pattern,
$._destructuring_pattern,
$.polyvar_type_pattern,
$._parenthesized_pattern,
)
),

_jsx_element: $ => choice($.jsx_element, $.jsx_self_closing_element),
Expand Down Expand Up @@ -1092,6 +1093,11 @@ module.exports = grammar({
$.block,
),

lazy_expression: $ => seq(
'lazy',
$.expression,
),

binary_expression: $ => choice(
...[
['&&', 'binary_and'],
Expand Down
19 changes: 19 additions & 0 deletions test/corpus/expressions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1408,3 +1408,22 @@ let f = ({name, _} as foo: T.t) => {}
(module_identifier)
(type_identifier))))))
body: (block))))

===========================================
Lazy Expression
===========================================

lazy { 1 }
lazy call()

---

(source_file
(expression_statement
(lazy_expression
(block
(expression_statement (number)))))
(expression_statement
(lazy_expression
(call_expression
(value_identifier) (arguments)))))
16 changes: 15 additions & 1 deletion test/corpus/let_bindings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -328,5 +328,19 @@ let module(Bar) = foo

(source_file
(let_binding
(module_unpack_pattern (module_identifier))
(module_pack (module_identifier))
(value_identifier)))

===========================================
Lazy Values
===========================================

let lazy x = lazy(1)

---

(source_file
(let_binding
(lazy_pattern (value_identifier))
(lazy_expression
(parenthesized_expression (number)))))

0 comments on commit 56dd030

Please sign in to comment.