Skip to content

Commit 78c4e9b

Browse files
authored
fix: allow "match" on LHS of named_expression (#153)
Fixes #150
1 parent 0d17ed6 commit 78c4e9b

File tree

6 files changed

+28999
-29484
lines changed

6 files changed

+28999
-29484
lines changed

grammar.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,16 @@ module.exports = grammar({
190190
),
191191

192192
named_expression: $ => seq(
193-
field('name', $.identifier),
193+
field('name', $._named_expresssion_lhs),
194194
':=',
195195
field('value', $.expression)
196196
),
197197

198+
_named_expresssion_lhs: $ => choice(
199+
$.identifier,
200+
alias('match', $.identifier), // ambiguity with match statement: only ":" at end of line decides if "match" keyword
201+
),
202+
198203
return_statement: $ => seq(
199204
'return',
200205
optional($._expressions)
@@ -499,7 +504,7 @@ module.exports = grammar({
499504

500505
pattern: $ => choice(
501506
$.identifier,
502-
alias("match", $.identifier), // ambiguity with match statement: only ":" at end of line decides if "match" keyword
507+
alias('match', $.identifier), // ambiguity with match statement: only ":" at end of line decides if "match" keyword
503508
$.keyword_identifier,
504509
$.subscript,
505510
$.attribute,

src/grammar.json

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@
604604
"name": "name",
605605
"content": {
606606
"type": "SYMBOL",
607-
"name": "identifier"
607+
"name": "_named_expresssion_lhs"
608608
}
609609
},
610610
{
@@ -621,6 +621,24 @@
621621
}
622622
]
623623
},
624+
"_named_expresssion_lhs": {
625+
"type": "CHOICE",
626+
"members": [
627+
{
628+
"type": "SYMBOL",
629+
"name": "identifier"
630+
},
631+
{
632+
"type": "ALIAS",
633+
"content": {
634+
"type": "STRING",
635+
"value": "match"
636+
},
637+
"named": true,
638+
"value": "identifier"
639+
}
640+
]
641+
},
624642
"return_statement": {
625643
"type": "SEQ",
626644
"members": [

0 commit comments

Comments
 (0)