tree-sitter-scala icon indicating copy to clipboard operation
tree-sitter-scala copied to clipboard

Reserved keywords (val, def) should be rejected as an identifier

Open eed3si9n opened this issue 3 years ago • 1 comments

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.

eed3si9n avatar Jan 05 '23 16:01 eed3si9n

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

susliko avatar May 26 '23 08:05 susliko