Fix stab clause ambiguities
This commit is contained in:
parent
bb5f90516e
commit
e35f31122f
16
grammar.js
16
grammar.js
|
@ -168,6 +168,14 @@ module.exports = grammar({
|
|||
// * stab arguments item in `arg1, left when right ->`
|
||||
[$.binary_operator, $._stab_clause_arguments_without_parentheses],
|
||||
|
||||
// Given `((arg1, arg2 • ,`, `arg3` expression can be either:
|
||||
// * stab parenthesised arguments item in `((arg1, arg2, arg3) ->)`
|
||||
// * stab non-parenthesised arguments item in `((arg1, arg2, arg3 ->))`
|
||||
[
|
||||
$._stab_clause_arguments_without_parentheses,
|
||||
$._stab_clause_arguments_with_parentheses,
|
||||
],
|
||||
|
||||
// Given `(-> • /`, stab can be either:
|
||||
// * stab clause operator in `(-> / / 2)`
|
||||
// * operator identifier in `(-> / 2)`
|
||||
|
@ -738,7 +746,13 @@ module.exports = grammar({
|
|||
"(",
|
||||
optional(
|
||||
choice(
|
||||
seq(sep1($._expression, ","), optional(seq(",", $.keywords))),
|
||||
seq(
|
||||
// We need the same expression precedence as below, so that we don't
|
||||
// discard this rule in favour of the one below. We use right precedence,
|
||||
// because in this case we can consume expression until the next comma
|
||||
sep1(prec.right(PREC.WHEN_OP, $._expression), ","),
|
||||
optional(seq(",", $.keywords))
|
||||
),
|
||||
$.keywords
|
||||
)
|
||||
),
|
||||
|
|
|
@ -5512,8 +5512,12 @@
|
|||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "PREC_RIGHT",
|
||||
"value": 20,
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_expression"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "REPEAT",
|
||||
|
@ -5525,9 +5529,13 @@
|
|||
"value": ","
|
||||
},
|
||||
{
|
||||
"type": "PREC_RIGHT",
|
||||
"value": 20,
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_expression"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -5874,6 +5882,10 @@
|
|||
"binary_operator",
|
||||
"_stab_clause_arguments_without_parentheses"
|
||||
],
|
||||
[
|
||||
"_stab_clause_arguments_without_parentheses",
|
||||
"_stab_clause_arguments_with_parentheses"
|
||||
],
|
||||
[
|
||||
"operator_identifier",
|
||||
"stab_clause"
|
||||
|
|
534152
src/parser.c
534152
src/parser.c
File diff suppressed because it is too large
Load Diff
|
@ -461,6 +461,7 @@ stab clause / edge cases / "when" in arguments
|
|||
|
||||
foo do
|
||||
a when b, c when d == e -> 1
|
||||
(a, a when b) -> 1
|
||||
end
|
||||
|
||||
---
|
||||
|
@ -479,6 +480,14 @@ end
|
|||
(binary_operator
|
||||
(identifier)
|
||||
(identifier)))
|
||||
(body
|
||||
(integer)))
|
||||
(stab_clause
|
||||
(arguments
|
||||
(identifier)
|
||||
(binary_operator
|
||||
(identifier)
|
||||
(identifier)))
|
||||
(body
|
||||
(integer))))))
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ fn x -> x end
|
|||
many arguments
|
||||
=====================================
|
||||
|
||||
fn(x, y) -> x + y end
|
||||
fn(x, y, z) -> x + y end
|
||||
|
||||
---
|
||||
|
||||
|
@ -77,6 +77,7 @@ fn(x, y) -> x + y end
|
|||
(anonymous_function
|
||||
(stab_clause
|
||||
(arguments
|
||||
(identifier)
|
||||
(identifier)
|
||||
(identifier))
|
||||
(body
|
||||
|
|
|
@ -96,7 +96,7 @@ trailing semicolon
|
|||
(integer)))
|
||||
|
||||
=====================================
|
||||
stab clauses
|
||||
stab clause / multiple clauses
|
||||
=====================================
|
||||
|
||||
(x -> x; y -> y
|
||||
|
@ -121,3 +121,110 @@ stab clauses
|
|||
(identifier))
|
||||
(body
|
||||
(identifier)))))
|
||||
|
||||
=====================================
|
||||
stab clause / multiple arguments
|
||||
=====================================
|
||||
|
||||
(x, y, z -> x)
|
||||
((x, y, z) -> x)
|
||||
|
||||
---
|
||||
|
||||
(source
|
||||
(block
|
||||
(stab_clause
|
||||
(arguments
|
||||
(identifier)
|
||||
(identifier)
|
||||
(identifier))
|
||||
(body
|
||||
(identifier))))
|
||||
(block
|
||||
(stab_clause
|
||||
(arguments
|
||||
(identifier)
|
||||
(identifier)
|
||||
(identifier))
|
||||
(body
|
||||
(identifier)))))
|
||||
|
||||
=====================================
|
||||
stab clause / guard
|
||||
=====================================
|
||||
|
||||
(x, y when x == y -> 1)
|
||||
((x, y when x == y -> 1))
|
||||
((x, y when x == y) -> 1)
|
||||
(x, y when x, z -> 1)
|
||||
((x, y when x, z -> 1))
|
||||
((x, y when x, z) -> 1)
|
||||
|
||||
---
|
||||
|
||||
(source
|
||||
(block
|
||||
(stab_clause
|
||||
(binary_operator
|
||||
(arguments
|
||||
(identifier)
|
||||
(identifier))
|
||||
(binary_operator
|
||||
(identifier)
|
||||
(identifier)))
|
||||
(body
|
||||
(integer))))
|
||||
(block
|
||||
(block
|
||||
(stab_clause
|
||||
(binary_operator
|
||||
(arguments
|
||||
(identifier)
|
||||
(identifier))
|
||||
(binary_operator
|
||||
(identifier)
|
||||
(identifier)))
|
||||
(body
|
||||
(integer)))))
|
||||
(block
|
||||
(stab_clause
|
||||
(arguments
|
||||
(identifier)
|
||||
(binary_operator
|
||||
(identifier)
|
||||
(binary_operator
|
||||
(identifier)
|
||||
(identifier))))
|
||||
(body
|
||||
(integer))))
|
||||
(block
|
||||
(stab_clause
|
||||
(arguments
|
||||
(identifier)
|
||||
(binary_operator
|
||||
(identifier)
|
||||
(identifier))
|
||||
(identifier))
|
||||
(body
|
||||
(integer))))
|
||||
(block
|
||||
(block
|
||||
(stab_clause
|
||||
(arguments
|
||||
(identifier)
|
||||
(binary_operator
|
||||
(identifier)
|
||||
(identifier))
|
||||
(identifier))
|
||||
(body
|
||||
(integer)))))
|
||||
(block
|
||||
(stab_clause
|
||||
(arguments
|
||||
(identifier)
|
||||
(binary_operator
|
||||
(identifier)
|
||||
(identifier))
|
||||
(identifier))
|
||||
(body
|
||||
(integer)))))
|
||||
|
|
Loading…
Reference in New Issue