Michael Davis 662426cd85
handle stab clauses without right-hand-sides
Currently a stab clause without a right-hand-side is parsed as an error:

```elixir
Enum.map(xs, fn x ->
end)
```

And the `end` token ends up not being highlighted as a keyword. The
compiler gives a warning about this syntax but it comes up pretty
often when editing (writing a `case` block for example).

Implementation-wise, this might be a bug in tree-sitter? `prec.right`
seems to fight with error recovery when the rightmost token(s) are
`optional`.

```elixir
fn ->
end
```

gets parsed as

```scm
(anonymous_function
  (stab_clause
    right: (body (identifier)))
  (MISSING "end"))
```

although the `optional` should allow this case. I've seen this in
other grammars and it seems like the way around it is to replace
the `prec.right` with a conflict.
2022-04-11 19:23:22 -05:00

73 lines
1.7 KiB
Elixir

fn x, y, z ->
# <- keyword
# ^ variable
# ^ punctuation.delimiter
# ^ variable
# ^ punctuation.delimiter
# ^ variable
# ^ operator
fn(a, b, c) ->
# <- keyword
# ^ punctuation.bracket
# ^ variable
# ^ punctuation.delimiter
# ^ variable
# ^ punctuation.delimiter
# ^ variable
# ^ punctuation.bracket
# ^ operator
&(x + y - z * a / &1 + b + div(&2, c))
#<- operator
#^ punctuation.bracket
# ^ variable
# ^ operator
# ^ variable
# ^ operator
# ^ variable
# ^ operator
# ^ variable
# ^ operator
# ^ operator
# ^ operator
# ^ variable
# ^ operator
# ^ function
# ^ punctuation.bracket
# ^ operator
# ^ punctuation.delimiter
# ^ variable
# ^ punctuation.bracket
# ^ punctuation.bracket
end
end
fn ->
# <- keyword
# ^ operator
end
# <- keyword
&Set.put(&1, &2)
# <- operator
# ^ module
# ^ operator
# ^ function
# ^ punctuation.bracket
# ^ operator
# ^ punctuation.delimiter
# ^ operator
# ^ punctuation.bracket
&( Set.put(&1, &1) )
#<- operator
#^ punctuation.bracket
# ^ module
# ^ operator
# ^ function
# ^ punctuation.bracket
# ^ operator
# ^ punctuation.delimiter
# ^ operator
# ^ punctuation.bracket
# ^ punctuation.bracket