PHP-Parser icon indicating copy to clipboard operation
PHP-Parser copied to clipboard

Error recovery from use nodes

Open felixfbecker opened this issue 9 years ago • 1 comments

use 
use What
use Whatever\
use Whatever\{} // cursor inside the braces
use Whatever\{Hello, } // cursor after the comma

Currently all result in

Syntax error, unexpected EOF, expecting ',' or ';' on line 4
==> Node dump:
array(
)
  1. Could be a Use node with an empty uses array
  2. Could be a Use node with a UseUse for What
  3. Could be a Use node with a UseUse with a Name where the last element of parts is an empty string, so that toString() returns Whatever\
  4. Could be a GroupUse node with an empty uses array
  5. Could be a GroupUse node with a UseUse for Hello and an Error node

I wanted to say thank you for adding all the other improvements so quickly! Being able to work with the parser nodes even in currently-edited documents is extremely powerful and I now have IDE-like completion for the common use cases (variables, keywords, methods, properties, classes, static class properties / methods / constants). That would have been so much harder with just tokenization.

felixfbecker avatar Nov 26 '16 10:11 felixfbecker

The second case is handled as part of https://github.com/nikic/PHP-Parser/commit/62877b5d14e4d2e4b213a9cdb25413b72bb6505a. The fifth case is handled with https://github.com/nikic/PHP-Parser/commit/a8eb2fc67516a641f4699af2e92b1260af10ce10 (as well as any other uses of invalid trailing commas). I did not include an Error node, in part because this particular case is actually going to be valid syntax in PHP 7.2.

nikic avatar Feb 09 '17 19:02 nikic