-
Notifications
You must be signed in to change notification settings - Fork 789
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
DotLambda: add parser recovery #16238
Conversation
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.
Thank you for this change.
I would also prefer to have these tests as syntaxtree tests.
Reason is, if anything changes in the SyntaxTree, the baselines can be easily re-created, whereas specific assertions need to be manually checked.
(which is not a big deal when there is 2 of them, but it is when we have hundreds)
4fdcfc4
to
601f0d0
Compare
Interesting observations on the commit 27e8d65: After adding recovery, in the following invalid code DotLambdas began to be parsed let a = ( upcast _ ) : obj let b = ( _ :> _ ) : obj let c = ( _ :> obj) Also parens expressions began to be parsed more correctly. |
Seeing the newly appeared |
Why, though? There're still errors on the incorrect code, so we aren't changing how any correct code is parsed, but surroundings are much better parsed in all the unfinished code examples. The purpose of the parser recovery is to parse as much code in the most correct way as we can, so all the analysis works with the best possible tree. We don't have any ambiguity here, so it's clear that |
I do not see a standalone |
Yes, but it should be something parseable when possible. And here it's unambiguously an unfinished dot lambda, as it's the only kind of an expression that could start with Even looking at the same examples, it's clear that none of It's the same kind of recovery as in the most of these PRs and it's what makes a much better IDE experience. It's OK to make assumptions about what an unfinished code may become after the the user types more into the editor. Not doing that makes analysis of surrounding code break. Consider |
Couldn't it also be an unfinished identifier starting with an underscore? |
It's a good example, thanks! I think would be much better to produce an identifier expression indeed. It's still going to be parsed as an atomic expression, so everything seems good. The downside is it'd require more checks here and there about |
Another option is to produce a generic error expression node covering So we have options to produce a dot lambda, an identifier, and a generic error node. I think the choice should be made based on these things:
|
If it were "just parsed" as an |
That's what I'd hope for! 🙂 |
The problem I see is it'd be really nice if we the tree could also show that this is an error node somehow in this case. Producing just an identifier moves the responsibility to various features to check it at a later stage, potentially duplicating code. The more I think about it, the more I'd prefer it to be parsed as a dotLambda (or an error, in the worst case) if features like code completion keep working, at least for now. Maybe I'd suggest to keep it as is in this PR if we know that there's no regression in code completion for |
Maybe |
27e8d65
to
8128b34
Compare
2918a7f
to
6a16eaa
Compare
@DedSec256 : Thanks for the changes! Are we ready to merge here? |
This PR adds parser recovery for the
SynExpr.DotLambda
for cases_.
and_
Special thanks to @auduchinok for the consultation.