Skip to content

Commit 108cdd5

Browse files
allow only one stab clause without a right-hand-side
Only one stab clause in a multi-stab-clause expression may be empty. Multiple is a syntax error. Co-authored-by: Jonatan Kłosko <jonatanklosko@gmail.com>
1 parent 662426c commit 108cdd5

File tree

2 files changed

+17
-34
lines changed

2 files changed

+17
-34
lines changed

grammar.js

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -159,16 +159,6 @@ module.exports = grammar({
159159
// * stab arguments item in `arg1, left when right ->`
160160
[$.binary_operator, $._stab_clause_arguments_without_parentheses],
161161

162-
// Given `( -> • \n`, the newline could be either:
163-
// * stab clause without a body
164-
// * stab clause with a body
165-
[$._stab_clause_without_body, $._stab_clause_with_body],
166-
167-
// Given `( -> • /`, `/` token could be either:
168-
// * stab clause with a body
169-
// * -> as an operator followed by `/`
170-
[$._stab_clause_with_body, $.operator_identifier],
171-
172162
// Given `((arg1, arg2 • ,`, `arg3` expression can be either:
173163
// * stab parenthesised arguments item in `((arg1, arg2, arg3) ->)`
174164
// * stab non-parenthesised arguments item in `((arg1, arg2, arg3 ->))`
@@ -739,20 +729,13 @@ module.exports = grammar({
739729
),
740730

741731
stab_clause: ($) =>
742-
choice($._stab_clause_with_body, $._stab_clause_without_body),
743-
744-
_stab_clause_with_body: ($) =>
745-
seq(
746-
optional(field("left", $._stab_clause_left)),
747-
field("operator", "->"),
748-
field("right", $.body)
749-
),
750-
751-
_stab_clause_without_body: ($) =>
752-
seq(
753-
optional(field("left", $._stab_clause_left)),
754-
field("operator", "->"),
755-
optional($._terminator)
732+
// Right precedence, because we want to consume body if any
733+
prec.right(
734+
seq(
735+
optional(field("left", $._stab_clause_left)),
736+
field("operator", "->"),
737+
optional(field("right", $.body))
738+
)
756739
),
757740

758741
_stab_clause_left: ($) =>
@@ -834,10 +817,13 @@ module.exports = grammar({
834817
),
835818

836819
body: ($) =>
837-
seq(
838-
optional($._terminator),
839-
sep1($._expression, $._terminator),
840-
optional($._terminator)
820+
choice(
821+
$._terminator,
822+
seq(
823+
optional($._terminator),
824+
sep1($._expression, $._terminator),
825+
optional($._terminator)
826+
)
841827
),
842828

843829
anonymous_function: ($) =>

test/corpus/do_end.txt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -684,12 +684,11 @@ end
684684
(integer))))))
685685

686686
=====================================
687-
stab clause / edge cases / empty right-hand-sides
687+
stab clause / edge cases / empty right-hand-side
688688
=====================================
689689

690690
fun do
691691
x ->
692-
y ->
693692
end
694693

695694
---
@@ -700,10 +699,8 @@ end
700699
(do_block
701700
(stab_clause
702701
(arguments
703-
(identifier)))
704-
(stab_clause
705-
(arguments
706-
(identifier))))))
702+
(identifier))
703+
(body)))))
707704

708705
=====================================
709706
pattern matching

0 commit comments

Comments
 (0)