Different error ranges dependent on next method return type #10
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Hello,
thanks in advance for your great work. I've got the following problem:
Consider the following two java programs:
and
Both programs contain the same syntax error in line 4.
But in the first case the error spans the whole lines 4, 5 and 6 (it seems to think that this is a LocalVariableDeclaration). Therefore the whole parsing tree is wrong after this error (the method "test2" is not recognized as method any longer).
In the second case the error spans line 4 only.
I put together a example that runs in the "try codemirror page" (see below). Just copy paste this and comment the code in the editor in or out.
Regards
Thomas.
How quickly the parser will find its way back after an error depends on the tokens after the error—because those are all it has to work with at that point. This is expected and I don't think it's a bug.
But why can LocalVariableDeclaration contain an closing }? I think the parser should be able to make out the code blocks in { } regardless of syntax errors.
The error recovery doesn't know anything about tokens' semantic meaning. It just looks for a way to insert/drop tokens that gets it back to something that parses. In this case what it does is dropping the closing bracket and parsing
s.String[] test2as a local declaration. That gets it far enough ahead that it considers the recovery a success and commits to it. The content after that will lead to new errors, but for performance reasons the distance the library parses ahead with multiple recovery attempts before committing to one is limited.Okay, but it's
s.}String[] test2which makes no sense, does it?
Why does it drop the closing bracket?
As I said, it drops the
}OK, but why does it drop the
}?I use the parser to parse java classes. To do all the semantics right and to provide autocompletion I need to parse the structure of the class first to get all attributes and methods. If the parser drops the
}, the structure is not recognized correctly. Therefore the users of my IDE get weird error messages like "there is no method xy" in certain circumstances.Because there is a syntax error and it needs to do something to try to recover and continue. Its recovery strategies for that include things like dropping tokens or making tokens up.