Skip to content

Commit 029db95

Browse files
committed
Fix arrow_function_expression
- Arrow functions cannot contain open tuples, so they should only allow closed assignments (like `let_statement`). - Rename `function_expression` to `arrow_function_expression`.
1 parent 238db56 commit 029db95

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

grammar.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ module.exports = grammar({
223223
$._operation,
224224
$.compound_assignment_expression,
225225
$.macrocall_expression,
226-
$.function_expression,
226+
$.arrow_function_expression,
227227
$.juxtaposition_expression,
228228
$.ternary_expression,
229229
$.operator,
@@ -864,7 +864,7 @@ module.exports = grammar({
864864
$._primary_expression,
865865
)),
866866

867-
function_expression: $ => prec.right(PREC.afunc, seq(
867+
arrow_function_expression: $ => prec.right(PREC.afunc, seq(
868868
choice(
869869
$.identifier,
870870
$.argument_list,
@@ -873,7 +873,7 @@ module.exports = grammar({
873873
'->',
874874
choice(
875875
$._expression,
876-
$.assignment,
876+
alias($._closed_assignment, $.assignment),
877877
),
878878
)),
879879

queries/highlights.scm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,17 +234,17 @@
234234
] @keyword.type)
235235

236236
; Operators & Punctuation
237-
[
238-
"->"
239-
(operator)
240-
] @operator
237+
(operator) @operator
241238

242239
(adjoint_expression
243240
"'" @operator)
244241

245242
(range_expression
246243
":" @operator)
247244

245+
(arrow_function_expression
246+
"->" @operator)
247+
248248
[
249249
"."
250250
"..."

test/corpus/expressions.txt

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -515,14 +515,15 @@ x -> x^2
515515
(x,y,z)-> 2*x + y - z
516516
()->3
517517
() -> (sleep(0.1); i += 1; l)
518+
a -> a = 2, 3
518519

519520
---
520521

521522
(source_file
522-
(function_expression
523+
(arrow_function_expression
523524
(identifier)
524525
(binary_expression (identifier) (operator) (integer_literal)))
525-
(function_expression
526+
(arrow_function_expression
526527
(argument_list (identifier) (identifier) (identifier))
527528
(binary_expression
528529
(binary_expression
@@ -531,13 +532,18 @@ x -> x^2
531532
(identifier))
532533
(operator)
533534
(identifier)))
534-
(function_expression
535+
(arrow_function_expression
535536
(argument_list)
536537
(integer_literal))
537-
(function_expression
538+
(arrow_function_expression
538539
(argument_list)
539540
(parenthesized_expression
540541
(call_expression (identifier) (argument_list (float_literal)))
541542
(compound_assignment_expression (identifier) (operator) (integer_literal))
542-
(identifier))))
543+
(identifier)))
544+
(open_tuple
545+
(arrow_function_expression
546+
(identifier)
547+
(assignment (identifier) (operator) (integer_literal)))
548+
(integer_literal)))
543549

0 commit comments

Comments
 (0)