tree-sitter-scala
tree-sitter-scala copied to clipboard
Reserved keywords (val, def) should be rejected as an identifier
steps
object A:
val val = val
tree-sitter parse examples/A.scala
problem
(compilation_unit [0, 0] - [2, 0]
(object_definition [0, 0] - [2, 0]
name: (identifier [0, 7] - [0, 8])
body: (template_body [0, 8] - [2, 0]
(val_definition [1, 2] - [1, 15]
pattern: (identifier [1, 6] - [1, 9])
value: (identifier [1, 12] - [1, 15])))))
expectation
val should be rejected as an identifier, and it should fail to parse.
notes
Given that Scala supports infix and postfix expression, combination of expr identifier expr would be parsed as an infix expression, and since we don't reject val, def, etc a small mistake in the grammar ends up spreading widely.
Looks like there's no straightforward way to disallow hard keywords as identifiers until this PR lands: https://github.com/tree-sitter/tree-sitter/pull/1635