Skip to content

Commit 9eebffb

Browse files
committed
fix: allow decorators before and in let bindings
1 parent caffe2d commit 9eebffb

File tree

2 files changed

+48
-10
lines changed

2 files changed

+48
-10
lines changed

grammar.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ module.exports = grammar({
7171
[$.record_field, $.record_pattern],
7272
[$.expression_statement, $.ternary_expression],
7373
[$._type_declaration],
74+
[$._let_binding],
7475
[$.let_binding, $.ternary_expression],
7576
[$.variant_identifier, $.module_identifier],
7677
[$.variant],
@@ -434,13 +435,19 @@ module.exports = grammar({
434435
'=',
435436
repeat($.decorator),
436437
$.expression,
437-
optional(seq(
438-
'and',
439-
$._let_binding,
440-
)),
438+
repeat(alias($._let_binding_and, $.let_binding)),
441439
)),
442440
),
443441

442+
_let_binding_and: $ => seq(
443+
// New line here not necessary terminates the statement,
444+
// show this doubt to the parser
445+
repeat($._newline),
446+
repeat($.decorator),
447+
'and',
448+
$._let_binding,
449+
),
450+
444451
_binding_pattern: $ => choice(
445452
$.value_identifier,
446453
$.tuple_pattern,

test/corpus/let_bindings.txt

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,12 @@ let a = 5 and b = 4
200200
(let_binding
201201
(value_identifier)
202202
(number)
203-
(value_identifier)
204-
(number)))
203+
(let_binding
204+
(value_identifier)
205+
(number))))
205206

206207
============================================
207-
And (Fuctions)
208+
And (Functions)
208209
============================================
209210

210211
let rec a = x => x + b(x) and b = y => y - 1
@@ -222,10 +223,40 @@ let rec a = x => x + b(x) and b = y => y - 1
222223
(value_identifier)
223224
(arguments
224225
(value_identifier)))))
225-
(value_identifier)
226-
(function
226+
(let_binding
227227
(value_identifier)
228-
(binary_expression
228+
(function
229+
(value_identifier)
230+
(binary_expression
231+
(value_identifier)
232+
(number))))))
233+
234+
============================================
235+
And (decorated)
236+
============================================
237+
238+
@one
239+
let rec a = b
240+
@two @three
241+
and b = c
242+
243+
@four and c = 42
244+
245+
---
246+
247+
(source_file
248+
(decorated
249+
(decorator (decorator_identifier))
250+
(let_binding
251+
(value_identifier)
252+
(value_identifier)
253+
(let_binding
254+
(decorator (decorator_identifier))
255+
(decorator (decorator_identifier))
256+
(value_identifier)
257+
(value_identifier))
258+
(let_binding
259+
(decorator (decorator_identifier))
229260
(value_identifier)
230261
(number)))))
231262

0 commit comments

Comments
 (0)