Permalink
Browse files

Fix parsing of new expressions in parenthesis

The new dereferencing syntaxes (new Foo)->bar and (new Foo)['bar'] were
causing a shift/reduce conflict with the '(' expr ')' rule. When
(new Foo) was encountered (without dereference operators following) the
parser thus threw a parse error.

The fix simply adds a special '(' new_expr ')' rule to expr. This does not
remove the shift/reduce conflict itself, but makes it irrelevant.

This fixes issue #20.
  • Loading branch information...
1 parent 25bbd69 commit e16513a0ebc781c06ddf0cecc18fa52274704713 @nikic nikic committed May 12, 2012
Showing with 429 additions and 411 deletions.
  1. +2 −0 grammar/zend_language_parser.phpy
  2. +416 −411 lib/PHPParser/Parser.php
  3. +11 −0 test/code/parser/expr/new.test
@@ -546,6 +546,8 @@ expr:
| expr T_IS_GREATER_OR_EQUAL expr { $$ = Expr_GreaterOrEqual[$1, $3]; }
| expr T_INSTANCEOF class_name_reference { $$ = Expr_Instanceof [$1, $3]; }
| '(' expr ')' { $$ = $2; }
+ /* we need a separate '(' new_expr ')' rule to avoid problems caused by a s/r conflict */
+ | '(' new_expr ')' { $$ = $2; }
| expr '?' expr ':' expr { $$ = Expr_Ternary[$1, $3, $5]; }
| expr '?' ':' expr { $$ = Expr_Ternary[$1, null, $4]; }
| T_ISSET '(' variables_list ')' { $$ = Expr_Isset[$3]; }
Oops, something went wrong.

0 comments on commit e16513a

Please sign in to comment.