Skip to content

Commit 09086fb

Browse files
committed
Support partial parsing of $foo->
Introduce Error node for this purpose.
1 parent ec614c9 commit 09086fb

File tree

6 files changed

+610
-558
lines changed

6 files changed

+610
-558
lines changed

grammar/php5.y

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -915,6 +915,7 @@ object_property:
915915
T_STRING { $$ = $1; }
916916
| '{' expr '}' { $$ = $2; }
917917
| variable_without_objects { $$ = $1; }
918+
| error { $$ = Expr\Error[]; }
918919
;
919920

920921
list_expr:

grammar/php7.y

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,7 @@ property_name:
793793
T_STRING { $$ = $1; }
794794
| '{' expr '}' { $$ = $2; }
795795
| simple_variable { $$ = Expr\Variable[$1]; }
796+
| error { $$ = Expr\Error[]; }
796797
;
797798

798799
list_expr:

lib/PhpParser/Node/Expr/Error.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace PhpParser\Node\Expr;
4+
5+
use PhpParser\Node\Expr;
6+
7+
/**
8+
* Error node used during parsing with error recovery.
9+
*
10+
* An error node may be placed at a position where an expression is required, but an error occurred.
11+
* Error nodes will not be present if the parser is run in throwOnError mode (the default).
12+
*/
13+
class Error extends Expr
14+
{
15+
/**
16+
* Constructs an error node.
17+
*
18+
* @param array $attributes Additional attributes
19+
*/
20+
public function __construct(array $attributes = array()) {
21+
parent::__construct($attributes);
22+
}
23+
24+
public function getSubNodeNames() {
25+
return array();
26+
}
27+
}

0 commit comments

Comments
 (0)