-
Notifications
You must be signed in to change notification settings - Fork 29
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
Error recovery/resilience #68
Comments
That sounds really great! Will the return type be |
Ruff is interested in having error recovery too but I believe that this will also require changes to the AST because errors should be represented in the tree in some way or another. A possible approach is to introduce a TypeScript uses synthesized nodes. I don't remember if they have |
I think that makes sense, yes. The lalrpop doc seems to suggest this. I also saw that the person who added the error recovery support to lalrpop implemented a language in rust called gluon, and its grammar uses error recovery so we can have a real example: https://github.com/gluon-lang/gluon/blob/be67982154319dea5e5486dfd1c46f8ca587c82e/parser/src/grammar.lalrpop
The errors will definitely need to be represented in the AST; just skipping over them (even if returning errors separately) is not an option IMO. As for BTW, I forgot to mention the lexer, but as matklad says, "Lexer itself should be resilient, but that’s easy — produce an Error token for anything which isn’t a valid token.". This can be the first step, though it's mostly orthogonal to parser error recovery. |
Currently, all of the parse functions return
Result<ast, ParseError>
. This means that if the file has a syntax error, we get the error and nothing else. However, there are some use cases in which having access to parts which did parse successfully would be beneficial:On the other hand, interpreters usually don't have too much use for this AFAIK.
lalrpop seems to have some support for error recovery: https://lalrpop.github.io/lalrpop/tutorial/008_error_recovery.html
Alex Kladov has written about error recovery, most recently here: https://matklad.github.io/2023/05/21/resilient-ll-parsing-tutorial.html
Is RustPython/Parser interested in error recovery or is it out of scope?
The text was updated successfully, but these errors were encountered: