Skip to content

Commit

Permalink
Support partial parsing of $foo->
Browse files Browse the repository at this point in the history
Introduce Error node for this purpose.
  • Loading branch information
nikic committed Jul 25, 2016
1 parent ec614c9 commit 09086fb
Show file tree
Hide file tree
Showing 6 changed files with 610 additions and 558 deletions.
1 change: 1 addition & 0 deletions grammar/php5.y
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,7 @@ object_property:
T_STRING { $$ = $1; }
| '{' expr '}' { $$ = $2; }
| variable_without_objects { $$ = $1; }
| error { $$ = Expr\Error[]; }
;

list_expr:
Expand Down
1 change: 1 addition & 0 deletions grammar/php7.y
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,7 @@ property_name:
T_STRING { $$ = $1; }
| '{' expr '}' { $$ = $2; }
| simple_variable { $$ = Expr\Variable[$1]; }
| error { $$ = Expr\Error[]; }
;

list_expr:
Expand Down
27 changes: 27 additions & 0 deletions lib/PhpParser/Node/Expr/Error.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace PhpParser\Node\Expr;

use PhpParser\Node\Expr;

/**
* Error node used during parsing with error recovery.
*
* An error node may be placed at a position where an expression is required, but an error occurred.
* Error nodes will not be present if the parser is run in throwOnError mode (the default).
*/
class Error extends Expr
{
/**
* Constructs an error node.
*
* @param array $attributes Additional attributes
*/
public function __construct(array $attributes = array()) {
parent::__construct($attributes);
}

public function getSubNodeNames() {
return array();
}
}
Loading

0 comments on commit 09086fb

Please sign in to comment.