tree-sitter-java
tree-sitter-java copied to clipboard
A class definition with wrong structure is replaced by ERROR
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.