-
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
More error recovery #262
Comments
It should be possible to implement this (not in a generic way, but handling specific cases like this one). However I'm not sure if it's worth the effort. I would generally recommend against using this library for implementing editor auto-complete (or rather, only use it for the analysis part) and detect this based on tokens instead. The current error recovery is more aimed at "be able to analyze other methods in this file while it's being modified" rather than "be able to analyze the currently modified expression". Editor-quality error recovery is a pretty hard nut and probably not in scope for this project. |
@nikic I also thought about using tokens only but that would mean I would have to implement a whole lot of stuff that is already so well implemented in this AST parser. It might be easy for something simple like |
I've just pushed a small improvement to error recovery in 96cbd48. This should handle the case of statements without a trailing semicolon, but will not handle the case of $foo-> // cursor here
$bar->foo(); this will parse as valid PHP If you want to work on better error recovery, this is done by sprinking additional For example, to support After modifying the grammar, you'll have to rebuild the parser, see https://github.com/nikic/PHP-Parser/tree/master/grammar#building-the-parser. (If you're on Windows, I can send you a kmyacc build.) Error recovery tests are here: https://github.com/nikic/PHP-Parser/blob/master/test/code/parser/errorHandling/recovery.test It may be convenient to test only the php7 parser, this can be done by putting a !!php7 at the top of the expected output. |
I just tried this out and this is absolutely amazing! Great work! |
I'm trying to use this library to provide autocompletion for an editor. This means often the code will not be complete:
the code above will parse with throwOnError: false, but only the first statement. It would be nice the parser could see the incomplete statement and guess a node, like
The text was updated successfully, but these errors were encountered: