-
Notifications
You must be signed in to change notification settings - Fork 76
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
Improve chevrotain parser error recovery #1822
base: main
Are you sure you want to change the base?
Conversation
@cdietrich Are you interested in testing this? I believe this should be beneficial for most adopters of Langium. I can create a next release of this change if you want to. |
bab10b4
to
f9f40ce
Compare
This PR is available as |
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.
I haven't seen any difference in error recovery with the example languages. Do you have an example where the recovery behaves differently?
One minor difference: in the statemachine example, when I insert state state
between the events
and the initialState
, the previous version showed two parser errors
Expecting token of type 'initialState' but found
state
.statemachine
Expecting end of file but foundstate
.
while the new version shows only one. But in both versions, the recovery does not work in this case: I get no cross-reference resolution for the rest of the file.
Me neither (at least with the examples). It might be that the only difference actually is related to the improved parser error message. Thinking further about this change, it's likely that this change mainly improves the error message behavior, as we likely end up at the same recovered parser state, but with less steps (and therefore fewer parser errors). |
While looking into the Chevrotain documentation on fault tolerance, I've noticed that we're not supposed to catch the errors thrown by Chevrotain ourselves, but let them propagate. We've been effectively starving the
catch
block in this method, which is in charge of actually recovering from the error.This results in some less-than-optimal behavior from Langium when it comes to error recovery. I've been playing around with this change using our example languages and it seems to behave pretty well. Refer to the additional comments to see why some of the changes were required.