nikic / nikic/PHP-Parser

Error recovery from use nodes

Open
#320 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
17.5k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue provides PHP examples for incomplete use and group-use statements but does not name files, tests, or a preferred AST result. Start by locating the parser entry point for use statements and existing error-recovery tests, then establish the intended node representation for each example before implementation.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.