-
-
Notifications
You must be signed in to change notification settings - Fork 781
fix(parser): allow excess tokens after expected EOF #5621
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
fix(parser): allow excess tokens after expected EOF #5621
Conversation
|
I'm a bit conflicted by the fix. It does the job, but I think it will have some impact on other tools like formatter or linter. I'm not sure though, why don't you add the same code in the grit formatter test suite, and see the result? Also, it's a symptom that the parser isn't recovering as expected. Ideally, any non-valid syntax should be placed inside a bogus node, even a generic one. With this fix, we're allowing our parser to not recover anymore properly, and as a "last resort" we allow adding everything to the EOF token. That's probably why we didn't allow that. |
CodSpeed Performance ReportMerging #5621 will not alter performanceComparing Summary
|
|
Yeah, I agree. I think the fix is still an improvement (almost everything is better than crashing), but ideally we try to avoid these situations. Maybe let's keep this fix, but try to enhance the Grit error recovery for this test case before merging? |
|
At least the error recovery is fixed too now, but I'd be tempted to keep the original fix as a "defence in depth" in case there similar issues lurking still. |
9a378dd to
7871f1d
Compare
ematipico
left a comment
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 good! As a nice to have, I wonder if we could log some kind of warning in the screenshot in case some content falls into the EOF token. This should help maintainers understand that they shouldn't have such cases
|
Good idea! I'll try that in a separate PR 👍 |
|
Hello @arendjr, |
|
@d0422 It will be in the upcoming 2.0 release, and we also have bi-weekly preview releases if you want it faster. They’re announced in the #releases channel on Discord. |
Summary
Fixes #5610.
This may be a somewhat controversial fix, so I'm going to need some advice on this one.
While investigating why the parser was crashing on the plugin in #5610, I noticed there was a panic inside
SyntaxKind::to_string()which only happened when the syntax kind was an EOL token. This could happen because both the GritQL and the GraphQL parsers have ap.expect(EOF)statement at the end of their parser.So my intuition was to fix this so that
SyntaxKind::to_string()can handle this gracefully and I've updated the codegen accordingly.It all worked out, and the panic is resolved now. But then I looked at the snapshot, and I see these excess tokens behind the EOF in the CST. I know this is not what we want, but then again... it seems we handle it gracefully now and the alternative would probably involve much more complex fixes in both these parsers. What do you think, @ematipico ?
Test Plan
Test case added.