Fix parsing issue with array accesses on object accesses ($x->y[z])

This commit is contained in:
nikic 2011-05-27 21:15:38 +02:00
parent bd88e4f555
commit ae3603d126
5 changed files with 15761 additions and 14833 deletions

File diff suppressed because it is too large Load Diff

View File

@ -571,11 +571,19 @@ class_name_reference:
;
dynamic_class_name_reference:
dynamic_class_name_reference T_OBJECT_OPERATOR object_property
{ $$ = new Node_Expr_PropertyFetch(array('var' => $1, 'name' => $3)); }
object_access_for_dcnr { $$ = $1; }
| base_variable { $$ = $1; }
;
object_access_for_dcnr:
| base_variable T_OBJECT_OPERATOR object_property
{ $$ = new Node_Expr_PropertyFetch(array('var' => $1, 'name' => $3)); }
| object_access_for_dcnr T_OBJECT_OPERATOR object_property
{ $$ = new Node_Expr_PropertyFetch(array('var' => $1, 'name' => $3)); }
| object_access_for_dcnr '[' dim_offset ']' { $$ = new Node_Expr_ArrayDimFetch(array('var' => $1, 'dim' => $3)); }
| object_access_for_dcnr '{' expr '}' { $$ = new Node_Expr_ArrayDimFetch(array('var' => $1, 'dim' => $3)); }
;
exit_expr:
/* empty */ { $$ = null; }
| '(' ')' { $$ = null; }
@ -651,14 +659,34 @@ expr:
;
variable:
variable T_OBJECT_OPERATOR object_property '(' function_call_argument_list ')'
{ $$ = new Node_Expr_MethodCall(array('var' => $1, 'name' => $3, 'args' => $5)); }
| variable T_OBJECT_OPERATOR object_property
{ $$ = new Node_Expr_PropertyFetch(array('var' => $1, 'name' => $3)); }
object_access { $$ = $1; }
| base_variable { $$ = $1; }
| function_call { $$ = $1; }
;
object_access:
base_variable T_OBJECT_OPERATOR object_property '(' function_call_argument_list ')'
{ $$ = new Node_Expr_MethodCall(array('var' => $1, 'name' => $3, 'args' => $5)); }
| function_call T_OBJECT_OPERATOR object_property '(' function_call_argument_list ')'
{ $$ = new Node_Expr_MethodCall(array('var' => $1, 'name' => $3, 'args' => $5)); }
| object_access T_OBJECT_OPERATOR object_property '(' function_call_argument_list ')'
{ $$ = new Node_Expr_MethodCall(array('var' => $1, 'name' => $3, 'args' => $5)); }
| object_access_arrayable { $$ = $1; }
| object_access_arrayable '(' function_call_argument_list ')'
{ $$ = new Node_Expr_FuncCall(array('func' => $1, 'args' => $3)); }
;
object_access_arrayable:
base_variable T_OBJECT_OPERATOR object_property
{ $$ = new Node_Expr_PropertyFetch(array('var' => $1, 'name' => $3)); }
| function_call T_OBJECT_OPERATOR object_property
{ $$ = new Node_Expr_PropertyFetch(array('var' => $1, 'name' => $3)); }
| object_access T_OBJECT_OPERATOR object_property
{ $$ = new Node_Expr_PropertyFetch(array('var' => $1, 'name' => $3)); }
| object_access_arrayable '[' dim_offset ']' { $$ = new Node_Expr_ArrayDimFetch(array('var' => $1, 'dim' => $3)); }
| object_access_arrayable '{' expr '}' { $$ = new Node_Expr_ArrayDimFetch(array('var' => $1, 'dim' => $3)); }
;
variable_without_objects:
reference_variable { $$ = $1; }
| '$' reference_variable { $$ = new Node_Variable(array('name' => $2)); }
@ -695,15 +723,9 @@ dim_offset:
;
object_property:
object_dim_list { $$ = $1; }
| variable_without_objects { $$ = $1; }
;
object_dim_list:
object_dim_list '[' dim_offset ']' { $$ = new Node_Expr_ArrayDimFetch(array('var' => $1, 'dim' => $3)); }
| object_dim_list '{' expr '}' { $$ = new Node_Expr_ArrayDimFetch(array('var' => $1, 'dim' => $3)); }
| T_STRING { $$ = $1; }
T_STRING { $$ = $1; }
| '{' expr '}' { $$ = $2; }
| variable_without_objects { $$ = $1; }
;
assignment_list:

View File

@ -571,11 +571,19 @@ class_name_reference:
;
dynamic_class_name_reference:
dynamic_class_name_reference T_OBJECT_OPERATOR object_property
{ $$ = Expr_PropertyFetch[var: $1, name: $3]; }
object_access_for_dcnr { $$ = $1; }
| base_variable { $$ = $1; }
;
object_access_for_dcnr:
| base_variable T_OBJECT_OPERATOR object_property
{ $$ = Expr_PropertyFetch[var: $1, name: $3]; }
| object_access_for_dcnr T_OBJECT_OPERATOR object_property
{ $$ = Expr_PropertyFetch[var: $1, name: $3]; }
| object_access_for_dcnr '[' dim_offset ']' { $$ = Expr_ArrayDimFetch[var: $1, dim: $3]; }
| object_access_for_dcnr '{' expr '}' { $$ = Expr_ArrayDimFetch[var: $1, dim: $3]; }
;
exit_expr:
/* empty */ { $$ = null; }
| '(' ')' { $$ = null; }
@ -651,14 +659,34 @@ expr:
;
variable:
variable T_OBJECT_OPERATOR object_property '(' function_call_argument_list ')'
{ $$ = Expr_MethodCall[var: $1, name: $3, args: $5]; }
| variable T_OBJECT_OPERATOR object_property
{ $$ = Expr_PropertyFetch[var: $1, name: $3]; }
object_access { $$ = $1; }
| base_variable { $$ = $1; }
| function_call { $$ = $1; }
;
object_access:
base_variable T_OBJECT_OPERATOR object_property '(' function_call_argument_list ')'
{ $$ = Expr_MethodCall[var: $1, name: $3, args: $5]; }
| function_call T_OBJECT_OPERATOR object_property '(' function_call_argument_list ')'
{ $$ = Expr_MethodCall[var: $1, name: $3, args: $5]; }
| object_access T_OBJECT_OPERATOR object_property '(' function_call_argument_list ')'
{ $$ = Expr_MethodCall[var: $1, name: $3, args: $5]; }
| object_access_arrayable { $$ = $1; }
| object_access_arrayable '(' function_call_argument_list ')'
{ $$ = Expr_FuncCall[func: $1, args: $3]; }
;
object_access_arrayable:
base_variable T_OBJECT_OPERATOR object_property
{ $$ = Expr_PropertyFetch[var: $1, name: $3]; }
| function_call T_OBJECT_OPERATOR object_property
{ $$ = Expr_PropertyFetch[var: $1, name: $3]; }
| object_access T_OBJECT_OPERATOR object_property
{ $$ = Expr_PropertyFetch[var: $1, name: $3]; }
| object_access_arrayable '[' dim_offset ']' { $$ = Expr_ArrayDimFetch[var: $1, dim: $3]; }
| object_access_arrayable '{' expr '}' { $$ = Expr_ArrayDimFetch[var: $1, dim: $3]; }
;
variable_without_objects:
reference_variable { $$ = $1; }
| '$' reference_variable { $$ = Variable[name: $2]; }
@ -695,15 +723,9 @@ dim_offset:
;
object_property:
object_dim_list { $$ = $1; }
| variable_without_objects { $$ = $1; }
;
object_dim_list:
object_dim_list '[' dim_offset ']' { $$ = Expr_ArrayDimFetch[var: $1, dim: $3]; }
| object_dim_list '{' expr '}' { $$ = Expr_ArrayDimFetch[var: $1, dim: $3]; }
| T_STRING { $$ = $1; }
T_STRING { $$ = $1; }
| '{' expr '}' { $$ = $2; }
| variable_without_objects { $$ = $1; }
;
assignment_list:

File diff suppressed because it is too large Load Diff

View File

@ -12,7 +12,12 @@ $parser->yydebug = false;
// Output Demo
$stmts = $parser->yyparse(new Lexer(
'<?php
x::$y[z];'
x::$y[z];
$x->y[z];
$x->y[z][k]->l()->m[t];
$x->y[z]();
$x->$y[z]();
$x->$$y[z]();'
),
function($msg) {
echo $msg, "\n";