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

Unused identifiers give weird errors when something comes after them #16

Open
idillon-sfl opened this issue Jan 19, 2024 · 2 comments
Open

Comments

@idillon-sfl
Copy link
Contributor

An unused identifier is invalid code and is expected to give errors. However, when some valid code come after it, the errors get weird and it make it difficult to provide something useful to the user.

This one is fine:

BAR='bar'
FOO
(recipe [0, 0] - [1, 3]
  (variable_assignment [0, 0] - [0, 9]
    (identifier [0, 0] - [0, 3])
    (literal [0, 4] - [0, 9]
      (string [0, 4] - [0, 9]
        (string_content [0, 5] - [0, 8]))))
  (ERROR [1, 0] - [1, 3]
    (identifier [1, 0] - [1, 3])))

These are not:
1.

FOO
BAR='bar'
(recipe [0, 0] - [1, 9]
  (variable_assignment [0, 0] - [1, 9]
    (identifier [0, 0] - [0, 3])
    (ERROR [1, 0] - [1, 3]
      (python_identifier [1, 0] - [1, 3]))
    (literal [1, 4] - [1, 9]
      (string [1, 4] - [1, 9]
        (string_content [1, 5] - [1, 8])))))
FOO
BAR() {
    
}
(recipe [0, 0] - [3, 1]
  (function_definition [0, 0] - [3, 1]
    (identifier [0, 0] - [0, 3])
    (ERROR [1, 0] - [1, 3]
      (python_identifier [1, 0] - [1, 3]))))
FOO
python bar() {

}
(recipe [0, 0] - [3, 1]
  (function_definition [0, 0] - [3, 1]
    (identifier [0, 0] - [0, 3])
    (ERROR [1, 0] - [1, 10]
      (python_identifier [1, 0] - [1, 6])
      (ERROR [1, 7] - [1, 10]))))

In each cases the FOO identifier is wrongly put inside a function_definition. A python_identifier also comes out of nowhere in 1. and 2.

@amaanq
Copy link
Member

amaanq commented Feb 1, 2024

This is difficult - as much as I'd like to fix this, I think the solution is to either rely on better output from incremental parsing (as the USER types, the tree isn't as malformed when just immediately parsing bad code), or to allow this as an invalid rule and it be denoted as such

@idillon-sfl
Copy link
Contributor Author

I noticed the following case does not give error, but still gives wrong parsing. It seems related.

foo:
python() {
}
(recipe [0, 0] - [2, 1]
  (function_definition [0, 0] - [2, 1]
    (identifier [0, 0] - [0, 3])
    (override [0, 3] - [1, 6]
      (identifier [1, 0] - [1, 6]))))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants