Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / nikic / php-parser / grammar / php5.y
index 79384381f7cecc9f71877b1948b49f974452074a..379cd3c75129ef0e5648afc77dc306ea65377e48 100644 (file)
@@ -16,7 +16,7 @@ top_statement_list_ex:
 
 top_statement_list:
       top_statement_list_ex
-          { makeNop($nop, $this->lookaheadStartAttributes);
+          { makeNop($nop, $this->lookaheadStartAttributes, $this->endAttributes);
             if ($nop !== null) { $1[] = $nop; } $$ = $1; }
 ;
 
@@ -35,9 +35,17 @@ semi_reserved:
     | 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:
@@ -49,6 +57,10 @@ namespace_name:
       namespace_name_parts                                  { $$ = Name[$1]; }
 ;
 
+plain_variable:
+      T_VARIABLE                                            { $$ = Expr\Variable[parseVar($1)]; }
+;
+
 top_statement:
       statement                                             { $$ = $1; }
     | function_declaration_statement                        { $$ = $1; }
@@ -109,7 +121,7 @@ inline_use_declarations:
 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); }
 ;
 
@@ -129,7 +141,7 @@ constant_declaration_list:
 ;
 
 constant_declaration:
-    T_STRING '=' static_scalar                              { $$ = Node\Const_[$1, $3]; }
+    identifier '=' static_scalar                            { $$ = Node\Const_[$1, $3]; }
 ;
 
 class_const_list:
@@ -138,7 +150,7 @@ class_const_list:
 ;
 
 class_const:
-    identifier '=' static_scalar                            { $$ = Node\Const_[$1, $3]; }
+    identifier_ex '=' static_scalar                         { $$ = Node\Const_[$1, $3]; }
 ;
 
 inner_statement_list_ex:
@@ -148,7 +160,7 @@ 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; }
 ;
 
@@ -166,7 +178,7 @@ non_empty_statement:
         if ($2) {
             $$ = $2; prependLeadingComments($$);
         } else {
-            makeNop($$, $this->startAttributeStack[#1]);
+            makeNop($$, $this->startAttributeStack[#1], $this->endAttributes);
             if (null === $$) { $$ = array(); }
         }
     }
@@ -185,12 +197,12 @@ non_empty_statement:
     | 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]]; }
@@ -200,16 +212,16 @@ non_empty_statement:
     | 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 */ }
 ;
 
@@ -219,8 +231,8 @@ catches:
 ;
 
 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:
@@ -244,18 +256,18 @@ optional_ellipsis:
 ;
 
 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]]; }
 ;
 
@@ -307,7 +319,7 @@ declare_list:
 ;
 
 declare_list_element:
-      T_STRING '=' static_scalar                            { $$ = Stmt\DeclareDeclare[$1, $3]; }
+      identifier '=' static_scalar                          { $$ = Stmt\DeclareDeclare[$1, $3]; }
 ;
 
 switch_case_list:
@@ -382,16 +394,16 @@ non_empty_parameter_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:
@@ -427,7 +439,7 @@ global_var_list:
 ;
 
 global_var:
-      T_VARIABLE                                            { $$ = Expr\Variable[parseVar($1)]; }
+      plain_variable                                        { $$ = $1; }
     | '$' variable                                          { $$ = Expr\Variable[$2]; }
     | '$' '{' expr '}'                                      { $$ = Expr\Variable[$3]; }
 ;
@@ -438,8 +450,8 @@ static_var_list:
 ;
 
 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:
@@ -451,7 +463,7 @@ class_statement:
       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]; }
@@ -470,22 +482,22 @@ trait_adaptation_list:
 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:
@@ -522,9 +534,13 @@ property_declaration_list:
     | 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:
@@ -665,6 +681,7 @@ anonymous_class:
       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]; }
@@ -683,30 +700,17 @@ lexical_var_list:
 ;
 
 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]; }
@@ -790,7 +794,7 @@ common_scalar:
 
 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]; }
@@ -835,7 +839,7 @@ static_operation:
 
 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]; }
 ;
 
@@ -914,9 +918,14 @@ static_property:
     | 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]; }
@@ -926,7 +935,7 @@ static_property_with_arrays:
 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]; }
 ;
 
@@ -936,7 +945,7 @@ dim_offset:
 ;
 
 object_property:
-      T_STRING                                              { $$ = $1; }
+      identifier                                            { $$ = $1; }
     | '{' expr '}'                                          { $$ = $2; }
     | variable_without_objects                              { $$ = $1; }
     | error                                                 { $$ = Expr\Error[]; $this->errorState = 2; }
@@ -985,25 +994,25 @@ encaps_string_part:
       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; }
 ;
 
 %%