Skip to content

Commit

Permalink
Add support for constant dereferencing (PHP 5.5)
Browse files Browse the repository at this point in the history
Examples: "foo"[2], [1, 2, 3][2]
  • Loading branch information
nikic committed Sep 7, 2012
1 parent 417a8bb commit 4259b44
Show file tree
Hide file tree
Showing 4 changed files with 732 additions and 513 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Version 0.9.3-dev
-----------------

* [PHP 5.5] Add support for constant array / string dereferencing.
Examples: `"foo"[2]`, `[1, 2, 3][2]`

* [PHP 5.5] Add support for `yield` expressions. This adds a new `Yield` expression type, with subnodes `key` and
`value`.

Expand Down
17 changes: 15 additions & 2 deletions grammar/zend_language_parser.phpy
Original file line number Diff line number Diff line change
Expand Up @@ -582,8 +582,8 @@ expr:
| T_EXIT exit_expr { $$ = Expr_Exit [$2]; }
| '@' expr { $$ = Expr_ErrorSuppress[$2]; }
| scalar { $$ = $1; }
| T_ARRAY '(' array_pair_list ')' { $$ = Expr_Array[$3]; }
| '[' array_pair_list ']' { $$ = Expr_Array[$2]; }
| array_expr { $$ = $1; }
| scalar_dereference { $$ = $1; }
| '`' backticks_expr '`' { $$ = Expr_ShellExec[$2]; }
| T_PRINT expr { $$ = Expr_Print[$2]; }
| T_YIELD { $$ = Expr_Yield[null, null]; }
Expand All @@ -603,6 +603,19 @@ yield_expr:
| T_YIELD expr T_DOUBLE_ARROW expr { $$ = Expr_Yield[$2, $4]; }
;

array_expr:
T_ARRAY '(' array_pair_list ')' { $$ = Expr_Array[$3]; }
| '[' array_pair_list ']' { $$ = Expr_Array[$2]; }
;

scalar_dereference:
array_expr '[' dim_offset ']' { $$ = Expr_ArrayDimFetch[$1, $3]; }
| T_CONSTANT_ENCAPSED_STRING '[' dim_offset ']'
{ $$ = Expr_ArrayDimFetch[Scalar_String::create($1, $attributes), $3]; }
| scalar_dereference '[' dim_offset ']' { $$ = Expr_ArrayDimFetch[$1, $3]; }
/* alternative array syntax missing intentionally */
;

new_expr:
T_NEW class_name_reference ctor_arguments { $$ = Expr_New[$2, $3]; }
;
Expand Down
Loading

0 comments on commit 4259b44

Please sign in to comment.