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>
This commit is contained in:
parent
662426cd85
commit
108cdd550f
28
grammar.js
28
grammar.js
|
@ -159,16 +159,6 @@ module.exports = grammar({
|
||||||
// * stab arguments item in `arg1, left when right ->`
|
// * stab arguments item in `arg1, left when right ->`
|
||||||
[$.binary_operator, $._stab_clause_arguments_without_parentheses],
|
[$.binary_operator, $._stab_clause_arguments_without_parentheses],
|
||||||
|
|
||||||
// Given `( -> • \n`, the newline could be either:
|
|
||||||
// * stab clause without a body
|
|
||||||
// * stab clause with a body
|
|
||||||
[$._stab_clause_without_body, $._stab_clause_with_body],
|
|
||||||
|
|
||||||
// Given `( -> • /`, `/` token could be either:
|
|
||||||
// * stab clause with a body
|
|
||||||
// * -> as an operator followed by `/`
|
|
||||||
[$._stab_clause_with_body, $.operator_identifier],
|
|
||||||
|
|
||||||
// Given `((arg1, arg2 • ,`, `arg3` expression can be either:
|
// Given `((arg1, arg2 • ,`, `arg3` expression can be either:
|
||||||
// * stab parenthesised arguments item in `((arg1, arg2, arg3) ->)`
|
// * stab parenthesised arguments item in `((arg1, arg2, arg3) ->)`
|
||||||
// * stab non-parenthesised arguments item in `((arg1, arg2, arg3 ->))`
|
// * stab non-parenthesised arguments item in `((arg1, arg2, arg3 ->))`
|
||||||
|
@ -739,20 +729,13 @@ module.exports = grammar({
|
||||||
),
|
),
|
||||||
|
|
||||||
stab_clause: ($) =>
|
stab_clause: ($) =>
|
||||||
choice($._stab_clause_with_body, $._stab_clause_without_body),
|
// Right precedence, because we want to consume body if any
|
||||||
|
prec.right(
|
||||||
_stab_clause_with_body: ($) =>
|
|
||||||
seq(
|
seq(
|
||||||
optional(field("left", $._stab_clause_left)),
|
optional(field("left", $._stab_clause_left)),
|
||||||
field("operator", "->"),
|
field("operator", "->"),
|
||||||
field("right", $.body)
|
optional(field("right", $.body))
|
||||||
),
|
)
|
||||||
|
|
||||||
_stab_clause_without_body: ($) =>
|
|
||||||
seq(
|
|
||||||
optional(field("left", $._stab_clause_left)),
|
|
||||||
field("operator", "->"),
|
|
||||||
optional($._terminator)
|
|
||||||
),
|
),
|
||||||
|
|
||||||
_stab_clause_left: ($) =>
|
_stab_clause_left: ($) =>
|
||||||
|
@ -834,10 +817,13 @@ module.exports = grammar({
|
||||||
),
|
),
|
||||||
|
|
||||||
body: ($) =>
|
body: ($) =>
|
||||||
|
choice(
|
||||||
|
$._terminator,
|
||||||
seq(
|
seq(
|
||||||
optional($._terminator),
|
optional($._terminator),
|
||||||
sep1($._expression, $._terminator),
|
sep1($._expression, $._terminator),
|
||||||
optional($._terminator)
|
optional($._terminator)
|
||||||
|
)
|
||||||
),
|
),
|
||||||
|
|
||||||
anonymous_function: ($) =>
|
anonymous_function: ($) =>
|
||||||
|
|
|
@ -684,12 +684,11 @@ end
|
||||||
(integer))))))
|
(integer))))))
|
||||||
|
|
||||||
=====================================
|
=====================================
|
||||||
stab clause / edge cases / empty right-hand-sides
|
stab clause / edge cases / empty right-hand-side
|
||||||
=====================================
|
=====================================
|
||||||
|
|
||||||
fun do
|
fun do
|
||||||
x ->
|
x ->
|
||||||
y ->
|
|
||||||
end
|
end
|
||||||
|
|
||||||
---
|
---
|
||||||
|
@ -700,10 +699,8 @@ end
|
||||||
(do_block
|
(do_block
|
||||||
(stab_clause
|
(stab_clause
|
||||||
(arguments
|
(arguments
|
||||||
(identifier)))
|
(identifier))
|
||||||
(stab_clause
|
(body)))))
|
||||||
(arguments
|
|
||||||
(identifier))))))
|
|
||||||
|
|
||||||
=====================================
|
=====================================
|
||||||
pattern matching
|
pattern matching
|
||||||
|
|
Loading…
Reference in New Issue