Split productions, unify {} dereferencing

This commit is contained in:
Nikita Popov 2020-02-22 20:54:55 +01:00
parent ad696ee75d
commit ca5f7c9761
3 changed files with 581 additions and 545 deletions

View File

@ -809,7 +809,7 @@ class_name_reference:
class_name_or_var:
class_name { $$ = $1; }
| dereferencable { $$ = $1; }
| fully_dereferencable { $$ = $1; }
;
exit_expr:
@ -831,9 +831,12 @@ ctor_arguments:
constant:
name { $$ = Expr\ConstFetch[$1]; }
| class_name_or_var T_PAAMAYIM_NEKUDOTAYIM identifier_ex
;
class_constant:
class_name_or_var T_PAAMAYIM_NEKUDOTAYIM identifier_ex
{ $$ = Expr\ClassConstFetch[$1, $3]; }
/* We interpret and isolated FOO:: as an unfinished class constant fetch. It could also be
/* We interpret an isolated FOO:: as an unfinished class constant fetch. It could also be
an unfinished static property fetch or unfinished scoped call. */
| class_name_or_var T_PAAMAYIM_NEKUDOTAYIM error
{ $$ = Expr\ClassConstFetch[$1, new Expr\Error(stackAttributes(#3))]; $this->errorState = 2; }
@ -871,6 +874,7 @@ scalar:
| T_NS_C { $$ = Scalar\MagicConst\Namespace_[]; }
| dereferencable_scalar { $$ = $1; }
| constant { $$ = $1; }
| class_constant { $$ = $1; }
| T_START_HEREDOC T_ENCAPSED_AND_WHITESPACE T_END_HEREDOC
{ $$ = $this->parseDocString($1, $2, $3, attributes(), stackAttributes(#3), true); }
| T_START_HEREDOC T_END_HEREDOC
@ -884,12 +888,18 @@ optional_expr:
| expr { $$ = $1; }
;
dereferencable:
fully_dereferencable:
variable { $$ = $1; }
| '(' expr ')' { $$ = $2; }
| dereferencable_scalar { $$ = $1; }
;
array_dereferencable:
fully_dereferencable { $$ = $1; }
| constant { $$ = $1; }
| class_constant { $$ = $1; }
;
callable_expr:
callable_variable { $$ = $1; }
| '(' expr ')' { $$ = $2; }
@ -898,18 +908,17 @@ callable_expr:
callable_variable:
simple_variable { $$ = Expr\Variable[$1]; }
| dereferencable '[' optional_expr ']' { $$ = Expr\ArrayDimFetch[$1, $3]; }
| constant '[' optional_expr ']' { $$ = Expr\ArrayDimFetch[$1, $3]; }
| dereferencable '{' expr '}' { $$ = Expr\ArrayDimFetch[$1, $3]; }
| array_dereferencable '[' optional_expr ']' { $$ = Expr\ArrayDimFetch[$1, $3]; }
| array_dereferencable '{' expr '}' { $$ = Expr\ArrayDimFetch[$1, $3]; }
| function_call { $$ = $1; }
| dereferencable T_OBJECT_OPERATOR property_name argument_list
| fully_dereferencable T_OBJECT_OPERATOR property_name argument_list
{ $$ = Expr\MethodCall[$1, $3, $4]; }
;
variable:
callable_variable { $$ = $1; }
| static_member { $$ = $1; }
| dereferencable T_OBJECT_OPERATOR property_name { $$ = Expr\PropertyFetch[$1, $3]; }
| fully_dereferencable T_OBJECT_OPERATOR property_name { $$ = Expr\PropertyFetch[$1, $3]; }
;
simple_variable:

File diff suppressed because it is too large Load Diff

View File

@ -4,6 +4,7 @@ Uniform variable syntax in PHP 7 (misc)
A::A[0];
A::A[0][1][2];
A::A{0};
"string"->length();
"foo$bar"[0];
"foo$bar"->length();
@ -57,6 +58,23 @@ array(
)
)
2: Stmt_Expression(
expr: Expr_ArrayDimFetch(
var: Expr_ClassConstFetch(
class: Name(
parts: array(
0: A
)
)
name: Identifier(
name: A
)
)
dim: Scalar_LNumber(
value: 0
)
)
)
3: Stmt_Expression(
expr: Expr_MethodCall(
var: Scalar_String(
value: string
@ -68,7 +86,7 @@ array(
)
)
)
3: Stmt_Expression(
4: Stmt_Expression(
expr: Expr_ArrayDimFetch(
var: Scalar_Encapsed(
parts: array(
@ -85,7 +103,7 @@ array(
)
)
)
4: Stmt_Expression(
5: Stmt_Expression(
expr: Expr_MethodCall(
var: Scalar_Encapsed(
parts: array(
@ -104,7 +122,7 @@ array(
)
)
)
5: Stmt_Expression(
6: Stmt_Expression(
expr: Expr_FuncCall(
name: Expr_ArrayDimFetch(
var: Expr_PropertyFetch(
@ -132,7 +150,7 @@ array(
)
)
)
6: Stmt_Expression(
7: Stmt_Expression(
expr: Expr_Assign(
var: Expr_ArrayDimFetch(
var: Expr_Array(