Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
eed3si9n opened this issue Jan 5, 2023 · 1 comment
Open
Labels
enhancement New feature or request

Comments

@eed3si9n
Copy link
Collaborator

eed3si9n commented Jan 5, 2023

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.

@susliko
Copy link
Collaborator

susliko commented May 26, 2023

Looks like there's no straightforward way to disallow hard keywords as identifiers until this PR lands: tree-sitter/tree-sitter#1635

@susliko susliko added the enhancement New feature or request label Jun 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants