-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Syntax error recovery #14695
Syntax error recovery #14695
Conversation
It turns out it's not needed. We can safely stop at a comma when in a statement sequence. It's not materially different from stopping a closing parenthesis.
48ad814
to
d56cf6a
Compare
- Drop Indented region only after seeing an OUTDENT node. This aligns region stack popping with the other closing tokens `]`, `)`, and `}` and thereby fixes a problem in `skip`. - When skipping, allow OUTDENT insertions even in n on-indent regions if the outdent matches a previous indent. This improves recovert when closing `]`, `)`, or `}` are missing. - When skipping an OUTDENT that matches a previous indent can discard nested regions. Fixes scala#14507
d56cf6a
to
4180269
Compare
Treat them as stop tokens only if there is a region that expects them
As for the other errors, don't issue an incomplete input error if the last error offset is the current offset.
a35236e
to
f190103
Compare
We now have the following handling of stop symbols in skip: - `)`, `]`, `}`: stop if there is a corresponding opening parenthesis - `,` : stop if we are in a `commaSeparated` production - undent : stop if indent width matches a previously seen indent width - `;`, nl : stop unconditionally, the parser will sync after the current statement
I also had to disable two scalatest tests: Not knowing scalatest, I was not able to figure out from the diagnostics which particular tests broke in the two suites, so I disabled them wholesale. I'll open a separate issue to bring back tests that are OK. |
We should do much better now with error recovery which should mean many fewer spurious errors in compiles and in the IDE. Previously, a mismatch of some kind of parenthesis could lead to a large part of the source being skipped without parsing. This in turn could lead to many follow-on type errors errors since definitions were not recognized. The new improvements are:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one minor nitpick, otherwise looks great!
val offset = in.offset | ||
if (in.token != token) | ||
def assumedOutdent = token == OUTDENT && in.token == EOF | ||
if in.token != token /*&& !assumedOutdent*/ then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like assumedOutdent
is not needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yes, that was a remainder of something else I tried that led nowhere.
This is a PR to improve syntax error recovery. It's meant to be integrated with one of the PRs by @adampauls to do trailing comma detection in Parser instead of Scanner.
I fixed the two CB issues that had illegal trailing commas. Here's the transcript of what I did. @anatoliykmetyuk might be able to point to a more worked out tutorial for this.
For specs2:
Fix problem in editor
Then, in the dotty directory:
Fixes #14507