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

A class definition with wrong structure is replaced by ERROR #127

Open
AdarWeidman opened this issue Nov 3, 2022 · 0 comments
Open

A class definition with wrong structure is replaced by ERROR #127

AdarWeidman opened this issue Nov 3, 2022 · 0 comments

Comments

@AdarWeidman
Copy link

Problem description

When parsing a badly-written code, I'd expect treesitter to have an error.
For example:

public class cl1
{

yields a "MISSING" error at the end:

program [0, 0] - [4, 0]
  class_declaration [0, 0] - [1, 1]
    modifiers [0, 0] - [0, 6]
    name: identifier [0, 13] - [0, 16]
    body: class_body [1, 0] - [1, 1]
      MISSING } [1, 1] - [1, 1]

Which makes sense.

BUT, if we mistakenly write something wrong there - I mistakenly closed the class with the wrong parentheses, ")" instead of "}" -

public class cl1
{
)

The class_declaration disappears and is replaced by "ERROR":

program [0, 0] - [3, 0]
  ERROR [0, 0] - [2, 1]
    modifiers [0, 0] - [0, 6]
    identifier [0, 13] - [0, 16]

Although the modifiers and identifiers are still there, so the system "knows" it's a class, just fails to communicate it.

The same happens in many other incomplete class structure, such as:

public class cl1
{
a = 3

But when adding a semi-colon, the class_declaration appears back.

I would expect to have the ERROR (or MISSING) in the bottom of the tree, and keep the class_declaration above, even possibly also have body.

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

1 participant