top_statement_list:
top_statement_list_ex
- { makeNop($nop, $this->lookaheadStartAttributes);
+ { makeNop($nop, $this->lookaheadStartAttributes, $this->endAttributes);
if ($nop !== null) { $1[] = $nop; } $$ = $1; }
;
| T_STATIC | T_ABSTRACT | T_FINAL | T_PRIVATE | T_PROTECTED | T_PUBLIC
;
+identifier_ex:
+ T_STRING { $$ = Node\Identifier[$1]; }
+ | semi_reserved { $$ = Node\Identifier[$1]; }
+;
+
identifier:
- T_STRING { $$ = $1; }
- | semi_reserved { $$ = $1; }
+ T_STRING { $$ = Node\Identifier[$1]; }
+;
+
+reserved_non_modifiers_identifier:
+ reserved_non_modifiers { $$ = Node\Identifier[$1]; }
;
namespace_name_parts:
namespace_name_parts { $$ = Name[$1]; }
;
+plain_variable:
+ T_VARIABLE { $$ = Expr\Variable[parseVar($1)]; }
+;
+
top_statement:
statement { $$ = $1; }
| function_declaration_statement { $$ = $1; }
unprefixed_use_declaration:
namespace_name
{ $$ = Stmt\UseUse[$1, null, Stmt\Use_::TYPE_UNKNOWN]; $this->checkUseUse($$, #1); }
- | namespace_name T_AS T_STRING
+ | namespace_name T_AS identifier
{ $$ = Stmt\UseUse[$1, $3, Stmt\Use_::TYPE_UNKNOWN]; $this->checkUseUse($$, #3); }
;
;
constant_declaration:
- T_STRING '=' static_scalar { $$ = Node\Const_[$1, $3]; }
+ identifier '=' static_scalar { $$ = Node\Const_[$1, $3]; }
;
class_const_list:
;
class_const:
- identifier '=' static_scalar { $$ = Node\Const_[$1, $3]; }
+ identifier_ex '=' static_scalar { $$ = Node\Const_[$1, $3]; }
;
inner_statement_list_ex:
inner_statement_list:
inner_statement_list_ex
- { makeNop($nop, $this->lookaheadStartAttributes);
+ { makeNop($nop, $this->lookaheadStartAttributes, $this->endAttributes);
if ($nop !== null) { $1[] = $nop; } $$ = $1; }
;
if ($2) {
$$ = $2; prependLeadingComments($$);
} else {
- makeNop($$, $this->startAttributeStack[#1]);
+ makeNop($$, $this->startAttributeStack[#1], $this->endAttributes);
if (null === $$) { $$ = array(); }
}
}
| T_CONTINUE expr ';' { $$ = Stmt\Continue_[$2]; }
| T_RETURN ';' { $$ = Stmt\Return_[null]; }
| T_RETURN expr ';' { $$ = Stmt\Return_[$2]; }
- | yield_expr ';' { $$ = $1; }
| T_GLOBAL global_var_list ';' { $$ = Stmt\Global_[$2]; }
| T_STATIC static_var_list ';' { $$ = Stmt\Static_[$2]; }
| T_ECHO expr_list ';' { $$ = Stmt\Echo_[$2]; }
| T_INLINE_HTML { $$ = Stmt\InlineHTML[$1]; }
- | expr ';' { $$ = $1; }
+ | yield_expr ';' { $$ = Stmt\Expression[$1]; }
+ | expr ';' { $$ = Stmt\Expression[$1]; }
| T_UNSET '(' variables_list ')' ';' { $$ = Stmt\Unset_[$3]; }
| T_FOREACH '(' expr T_AS foreach_variable ')' foreach_statement
{ $$ = Stmt\Foreach_[$3, $5[0], ['keyVar' => null, 'byRef' => $5[1], 'stmts' => $7]]; }
| T_TRY '{' inner_statement_list '}' catches optional_finally
{ $$ = Stmt\TryCatch[$3, $5, $6]; $this->checkTryCatch($$); }
| T_THROW expr ';' { $$ = Stmt\Throw_[$2]; }
- | T_GOTO T_STRING ';' { $$ = Stmt\Goto_[$2]; }
- | T_STRING ':' { $$ = Stmt\Label[$1]; }
- | expr error { $$ = $1; }
+ | T_GOTO identifier ';' { $$ = Stmt\Goto_[$2]; }
+ | identifier ':' { $$ = Stmt\Label[$1]; }
+ | expr error { $$ = Stmt\Expression[$1]; }
| error { $$ = array(); /* means: no statement */ }
;
statement:
non_empty_statement { $$ = $1; }
| ';'
- { makeNop($$, $this->startAttributeStack[#1]);
+ { makeNop($$, $this->startAttributeStack[#1], $this->endAttributes);
if ($$ === null) $$ = array(); /* means: no statement */ }
;
;
catch:
- T_CATCH '(' name T_VARIABLE ')' '{' inner_statement_list '}'
- { $$ = Stmt\Catch_[array($3), parseVar($4), $7]; }
+ T_CATCH '(' name plain_variable ')' '{' inner_statement_list '}'
+ { $$ = Stmt\Catch_[array($3), $4, $7]; }
;
optional_finally:
;
function_declaration_statement:
- T_FUNCTION optional_ref T_STRING '(' parameter_list ')' optional_return_type '{' inner_statement_list '}'
+ T_FUNCTION optional_ref identifier '(' parameter_list ')' optional_return_type '{' inner_statement_list '}'
{ $$ = Stmt\Function_[$3, ['byRef' => $2, 'params' => $5, 'returnType' => $7, 'stmts' => $9]]; }
;
class_declaration_statement:
- class_entry_type T_STRING extends_from implements_list '{' class_statement_list '}'
+ class_entry_type identifier extends_from implements_list '{' class_statement_list '}'
{ $$ = Stmt\Class_[$2, ['type' => $1, 'extends' => $3, 'implements' => $4, 'stmts' => $6]];
$this->checkClass($$, #2); }
- | T_INTERFACE T_STRING interface_extends_list '{' class_statement_list '}'
+ | T_INTERFACE identifier interface_extends_list '{' class_statement_list '}'
{ $$ = Stmt\Interface_[$2, ['extends' => $3, 'stmts' => $5]];
$this->checkInterface($$, #2); }
- | T_TRAIT T_STRING '{' class_statement_list '}'
+ | T_TRAIT identifier '{' class_statement_list '}'
{ $$ = Stmt\Trait_[$2, ['stmts' => $4]]; }
;
;
declare_list_element:
- T_STRING '=' static_scalar { $$ = Stmt\DeclareDeclare[$1, $3]; }
+ identifier '=' static_scalar { $$ = Stmt\DeclareDeclare[$1, $3]; }
;
switch_case_list:
;
parameter:
- optional_param_type optional_ref optional_ellipsis T_VARIABLE
- { $$ = Node\Param[parseVar($4), null, $1, $2, $3]; $this->checkParam($$); }
- | optional_param_type optional_ref optional_ellipsis T_VARIABLE '=' static_scalar
- { $$ = Node\Param[parseVar($4), $6, $1, $2, $3]; $this->checkParam($$); }
+ optional_param_type optional_ref optional_ellipsis plain_variable
+ { $$ = Node\Param[$4, null, $1, $2, $3]; $this->checkParam($$); }
+ | optional_param_type optional_ref optional_ellipsis plain_variable '=' static_scalar
+ { $$ = Node\Param[$4, $6, $1, $2, $3]; $this->checkParam($$); }
;
type:
name { $$ = $1; }
- | T_ARRAY { $$ = 'array'; }
- | T_CALLABLE { $$ = 'callable'; }
+ | T_ARRAY { $$ = Node\Identifier['array']; }
+ | T_CALLABLE { $$ = Node\Identifier['callable']; }
;
optional_param_type:
;
global_var:
- T_VARIABLE { $$ = Expr\Variable[parseVar($1)]; }
+ plain_variable { $$ = $1; }
| '$' variable { $$ = Expr\Variable[$2]; }
| '$' '{' expr '}' { $$ = Expr\Variable[$3]; }
;
;
static_var:
- T_VARIABLE { $$ = Stmt\StaticVar[parseVar($1), null]; }
- | T_VARIABLE '=' static_scalar { $$ = Stmt\StaticVar[parseVar($1), $3]; }
+ plain_variable { $$ = Stmt\StaticVar[$1, null]; }
+ | plain_variable '=' static_scalar { $$ = Stmt\StaticVar[$1, $3]; }
;
class_statement_list:
variable_modifiers property_declaration_list ';'
{ $$ = Stmt\Property[$1, $2]; $this->checkProperty($$, #1); }
| T_CONST class_const_list ';' { $$ = Stmt\ClassConst[$2, 0]; }
- | method_modifiers T_FUNCTION optional_ref identifier '(' parameter_list ')' optional_return_type method_body
+ | method_modifiers T_FUNCTION optional_ref identifier_ex '(' parameter_list ')' optional_return_type method_body
{ $$ = Stmt\ClassMethod[$4, ['type' => $1, 'byRef' => $3, 'params' => $6, 'returnType' => $8, 'stmts' => $9]];
$this->checkClassMethod($$, #1); }
| T_USE class_name_list trait_adaptations { $$ = Stmt\TraitUse[$2, $3]; }
trait_adaptation:
trait_method_reference_fully_qualified T_INSTEADOF class_name_list ';'
{ $$ = Stmt\TraitUseAdaptation\Precedence[$1[0], $1[1], $3]; }
- | trait_method_reference T_AS member_modifier identifier ';'
+ | trait_method_reference T_AS member_modifier identifier_ex ';'
{ $$ = Stmt\TraitUseAdaptation\Alias[$1[0], $1[1], $3, $4]; }
| trait_method_reference T_AS member_modifier ';'
{ $$ = Stmt\TraitUseAdaptation\Alias[$1[0], $1[1], $3, null]; }
- | trait_method_reference T_AS T_STRING ';'
+ | trait_method_reference T_AS identifier ';'
{ $$ = Stmt\TraitUseAdaptation\Alias[$1[0], $1[1], null, $3]; }
- | trait_method_reference T_AS reserved_non_modifiers ';'
+ | trait_method_reference T_AS reserved_non_modifiers_identifier ';'
{ $$ = Stmt\TraitUseAdaptation\Alias[$1[0], $1[1], null, $3]; }
;
trait_method_reference_fully_qualified:
- name T_PAAMAYIM_NEKUDOTAYIM identifier { $$ = array($1, $3); }
+ name T_PAAMAYIM_NEKUDOTAYIM identifier_ex { $$ = array($1, $3); }
;
trait_method_reference:
trait_method_reference_fully_qualified { $$ = $1; }
- | identifier { $$ = array(null, $1); }
+ | identifier_ex { $$ = array(null, $1); }
;
method_body:
| property_declaration_list ',' property_declaration { push($1, $3); }
;
+property_decl_name:
+ T_VARIABLE { $$ = Node\VarLikeIdentifier[parseVar($1)]; }
+;
+
property_declaration:
- T_VARIABLE { $$ = Stmt\PropertyProperty[parseVar($1), null]; }
- | T_VARIABLE '=' static_scalar { $$ = Stmt\PropertyProperty[parseVar($1), $3]; }
+ property_decl_name { $$ = Stmt\PropertyProperty[$1, null]; }
+ | property_decl_name '=' static_scalar { $$ = Stmt\PropertyProperty[$1, $3]; }
;
expr_list:
T_CLASS ctor_arguments extends_from implements_list '{' class_statement_list '}'
{ $$ = array(Stmt\Class_[null, ['type' => 0, 'extends' => $3, 'implements' => $4, 'stmts' => $6]], $2);
$this->checkClass($$[0], -1); }
+;
new_expr:
T_NEW class_name_reference ctor_arguments { $$ = Expr\New_[$2, $3]; }
;
lexical_var:
- optional_ref T_VARIABLE { $$ = Expr\ClosureUse[parseVar($2), $1]; }
+ optional_ref plain_variable { $$ = Expr\ClosureUse[$2, $1]; }
;
function_call:
name argument_list { $$ = Expr\FuncCall[$1, $2]; }
- | class_name_or_var T_PAAMAYIM_NEKUDOTAYIM identifier argument_list
+ | class_name_or_var T_PAAMAYIM_NEKUDOTAYIM identifier_ex argument_list
{ $$ = Expr\StaticCall[$1, $3, $4]; }
| class_name_or_var T_PAAMAYIM_NEKUDOTAYIM '{' expr '}' argument_list
{ $$ = Expr\StaticCall[$1, $4, $6]; }
- | static_property argument_list {
- if ($1 instanceof Node\Expr\StaticPropertyFetch) {
- $$ = Expr\StaticCall[$1->class, Expr\Variable[$1->name], $2];
- } elseif ($1 instanceof Node\Expr\ArrayDimFetch) {
- $tmp = $1;
- while ($tmp->var instanceof Node\Expr\ArrayDimFetch) {
- $tmp = $tmp->var;
- }
-
- $$ = Expr\StaticCall[$tmp->var->class, $1, $2];
- $tmp->var = Expr\Variable[$tmp->var->name];
- } else {
- throw new \Exception;
- }
- }
+ | static_property argument_list
+ { $$ = $this->fixupPhp5StaticPropCall($1, $2, attributes()); }
| variable_without_objects argument_list
{ $$ = Expr\FuncCall[$1, $2]; }
| function_call '[' dim_offset ']' { $$ = Expr\ArrayDimFetch[$1, $3]; }
static_scalar:
common_scalar { $$ = $1; }
- | class_name T_PAAMAYIM_NEKUDOTAYIM identifier { $$ = Expr\ClassConstFetch[$1, $3]; }
+ | class_name T_PAAMAYIM_NEKUDOTAYIM identifier_ex { $$ = Expr\ClassConstFetch[$1, $3]; }
| name { $$ = Expr\ConstFetch[$1]; }
| T_ARRAY '(' static_array_pair_list ')' { $$ = Expr\Array_[$3]; }
| '[' static_array_pair_list ']' { $$ = Expr\Array_[$2]; }
constant:
name { $$ = Expr\ConstFetch[$1]; }
- | class_name_or_var T_PAAMAYIM_NEKUDOTAYIM identifier
+ | class_name_or_var T_PAAMAYIM_NEKUDOTAYIM identifier_ex
{ $$ = Expr\ClassConstFetch[$1, $3]; }
;
| static_property_with_arrays { $$ = $1; }
;
+static_property_simple_name:
+ T_VARIABLE
+ { $var = parseVar($1); $$ = \is_string($var) ? Node\VarLikeIdentifier[$var] : $var; }
+;
+
static_property_with_arrays:
- class_name_or_var T_PAAMAYIM_NEKUDOTAYIM T_VARIABLE
- { $$ = Expr\StaticPropertyFetch[$1, parseVar($3)]; }
+ class_name_or_var T_PAAMAYIM_NEKUDOTAYIM static_property_simple_name
+ { $$ = Expr\StaticPropertyFetch[$1, $3]; }
| class_name_or_var T_PAAMAYIM_NEKUDOTAYIM '$' '{' expr '}'
{ $$ = Expr\StaticPropertyFetch[$1, $5]; }
| static_property_with_arrays '[' dim_offset ']' { $$ = Expr\ArrayDimFetch[$1, $3]; }
reference_variable:
reference_variable '[' dim_offset ']' { $$ = Expr\ArrayDimFetch[$1, $3]; }
| reference_variable '{' expr '}' { $$ = Expr\ArrayDimFetch[$1, $3]; }
- | T_VARIABLE { $$ = Expr\Variable[parseVar($1)]; }
+ | plain_variable { $$ = $1; }
| '$' '{' expr '}' { $$ = Expr\Variable[$3]; }
;
;
object_property:
- T_STRING { $$ = $1; }
+ identifier { $$ = $1; }
| '{' expr '}' { $$ = $2; }
| variable_without_objects { $$ = $1; }
| error { $$ = Expr\Error[]; $this->errorState = 2; }
T_ENCAPSED_AND_WHITESPACE { $$ = Scalar\EncapsedStringPart[$1]; }
;
-encaps_base_var:
- T_VARIABLE { $$ = Expr\Variable[parseVar($1)]; }
+encaps_str_varname:
+ T_STRING_VARNAME { $$ = Expr\Variable[$1]; }
;
encaps_var:
- encaps_base_var { $$ = $1; }
- | encaps_base_var '[' encaps_var_offset ']' { $$ = Expr\ArrayDimFetch[$1, $3]; }
- | encaps_base_var T_OBJECT_OPERATOR T_STRING { $$ = Expr\PropertyFetch[$1, $3]; }
+ plain_variable { $$ = $1; }
+ | plain_variable '[' encaps_var_offset ']' { $$ = Expr\ArrayDimFetch[$1, $3]; }
+ | plain_variable T_OBJECT_OPERATOR identifier { $$ = Expr\PropertyFetch[$1, $3]; }
| T_DOLLAR_OPEN_CURLY_BRACES expr '}' { $$ = Expr\Variable[$2]; }
| T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME '}' { $$ = Expr\Variable[$2]; }
- | T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME '[' expr ']' '}'
- { $$ = Expr\ArrayDimFetch[Expr\Variable[$2], $4]; }
+ | T_DOLLAR_OPEN_CURLY_BRACES encaps_str_varname '[' expr ']' '}'
+ { $$ = Expr\ArrayDimFetch[$2, $4]; }
| T_CURLY_OPEN variable '}' { $$ = $2; }
;
encaps_var_offset:
T_STRING { $$ = Scalar\String_[$1]; }
| T_NUM_STRING { $$ = $this->parseNumString($1, attributes()); }
- | T_VARIABLE { $$ = Expr\Variable[parseVar($1)]; }
+ | plain_variable { $$ = $1; }
;
%%