mirror of
https://github.com/danog/PHP-Parser.git
synced 2024-11-26 11:54:52 +01:00
Migrate grammar to use PHP 8 T_NAME_* tokens
This will break everything on PHP < 8.
This commit is contained in:
parent
2d1998938c
commit
a63b495fe6
@ -49,13 +49,14 @@ reserved_non_modifiers_identifier:
|
||||
reserved_non_modifiers { $$ = Node\Identifier[$1]; }
|
||||
;
|
||||
|
||||
namespace_name_parts:
|
||||
T_STRING { init($1); }
|
||||
| namespace_name_parts T_NS_SEPARATOR T_STRING { push($1, $3); }
|
||||
namespace_name:
|
||||
T_STRING { $$ = Name[$1]; }
|
||||
| T_NAME_QUALIFIED { $$ = Name[$1]; }
|
||||
;
|
||||
|
||||
namespace_name:
|
||||
namespace_name_parts { $$ = Name[$1]; }
|
||||
legacy_namespace_name:
|
||||
namespace_name { $$ = $1; }
|
||||
| T_NAME_FULLY_QUALIFIED { $$ = Name[substr($1, 1)]; }
|
||||
;
|
||||
|
||||
plain_variable:
|
||||
@ -91,16 +92,11 @@ use_type:
|
||||
| T_CONST { $$ = Stmt\Use_::TYPE_CONSTANT; }
|
||||
;
|
||||
|
||||
/* Using namespace_name_parts here to avoid s/r conflict on T_NS_SEPARATOR */
|
||||
group_use_declaration:
|
||||
T_USE use_type namespace_name_parts T_NS_SEPARATOR '{' unprefixed_use_declarations '}'
|
||||
{ $$ = Stmt\GroupUse[new Name($3, stackAttributes(#3)), $6, $2]; }
|
||||
| T_USE use_type T_NS_SEPARATOR namespace_name_parts T_NS_SEPARATOR '{' unprefixed_use_declarations '}'
|
||||
{ $$ = Stmt\GroupUse[new Name($4, stackAttributes(#4)), $7, $2]; }
|
||||
| T_USE namespace_name_parts T_NS_SEPARATOR '{' inline_use_declarations '}'
|
||||
{ $$ = Stmt\GroupUse[new Name($2, stackAttributes(#2)), $5, Stmt\Use_::TYPE_UNKNOWN]; }
|
||||
| T_USE T_NS_SEPARATOR namespace_name_parts T_NS_SEPARATOR '{' inline_use_declarations '}'
|
||||
{ $$ = Stmt\GroupUse[new Name($3, stackAttributes(#3)), $6, Stmt\Use_::TYPE_UNKNOWN]; }
|
||||
T_USE use_type legacy_namespace_name T_NS_SEPARATOR '{' unprefixed_use_declarations '}'
|
||||
{ $$ = Stmt\GroupUse[$3, $6, $2]; }
|
||||
| T_USE legacy_namespace_name T_NS_SEPARATOR '{' inline_use_declarations '}'
|
||||
{ $$ = Stmt\GroupUse[$2, $5, Stmt\Use_::TYPE_UNKNOWN]; }
|
||||
;
|
||||
|
||||
unprefixed_use_declarations:
|
||||
@ -127,8 +123,10 @@ unprefixed_use_declaration:
|
||||
;
|
||||
|
||||
use_declaration:
|
||||
unprefixed_use_declaration { $$ = $1; }
|
||||
| T_NS_SEPARATOR unprefixed_use_declaration { $$ = $2; }
|
||||
legacy_namespace_name
|
||||
{ $$ = Stmt\UseUse[$1, null, Stmt\Use_::TYPE_UNKNOWN]; $this->checkUseUse($$, #1); }
|
||||
| legacy_namespace_name T_AS identifier
|
||||
{ $$ = Stmt\UseUse[$1, $3, Stmt\Use_::TYPE_UNKNOWN]; $this->checkUseUse($$, #3); }
|
||||
;
|
||||
|
||||
inline_use_declaration:
|
||||
@ -734,9 +732,10 @@ class_name:
|
||||
;
|
||||
|
||||
name:
|
||||
namespace_name_parts { $$ = Name[$1]; }
|
||||
| T_NS_SEPARATOR namespace_name_parts { $$ = Name\FullyQualified[$2]; }
|
||||
| T_NAMESPACE T_NS_SEPARATOR namespace_name_parts { $$ = Name\Relative[$3]; }
|
||||
T_STRING { $$ = Name[$1]; }
|
||||
| T_NAME_QUALIFIED { $$ = Name[$1]; }
|
||||
| T_NAME_FULLY_QUALIFIED { $$ = Name\FullyQualified[substr($1, 1)]; }
|
||||
| T_NAME_RELATIVE { $$ = Name\Relative[substr($1, 10)]; }
|
||||
;
|
||||
|
||||
class_name_reference:
|
||||
|
@ -49,13 +49,14 @@ reserved_non_modifiers_identifier:
|
||||
reserved_non_modifiers { $$ = Node\Identifier[$1]; }
|
||||
;
|
||||
|
||||
namespace_name_parts:
|
||||
T_STRING { init($1); }
|
||||
| namespace_name_parts T_NS_SEPARATOR T_STRING { push($1, $3); }
|
||||
namespace_name:
|
||||
T_STRING { $$ = Name[$1]; }
|
||||
| T_NAME_QUALIFIED { $$ = Name[$1]; }
|
||||
;
|
||||
|
||||
namespace_name:
|
||||
namespace_name_parts { $$ = Name[$1]; }
|
||||
legacy_namespace_name:
|
||||
namespace_name { $$ = $1; }
|
||||
| T_NAME_FULLY_QUALIFIED { $$ = Name[substr($1, 1)]; }
|
||||
;
|
||||
|
||||
plain_variable:
|
||||
@ -105,16 +106,11 @@ use_type:
|
||||
| T_CONST { $$ = Stmt\Use_::TYPE_CONSTANT; }
|
||||
;
|
||||
|
||||
/* Using namespace_name_parts here to avoid s/r conflict on T_NS_SEPARATOR */
|
||||
group_use_declaration:
|
||||
T_USE use_type namespace_name_parts T_NS_SEPARATOR '{' unprefixed_use_declarations '}'
|
||||
{ $$ = Stmt\GroupUse[new Name($3, stackAttributes(#3)), $6, $2]; }
|
||||
| T_USE use_type T_NS_SEPARATOR namespace_name_parts T_NS_SEPARATOR '{' unprefixed_use_declarations '}'
|
||||
{ $$ = Stmt\GroupUse[new Name($4, stackAttributes(#4)), $7, $2]; }
|
||||
| T_USE namespace_name_parts T_NS_SEPARATOR '{' inline_use_declarations '}'
|
||||
{ $$ = Stmt\GroupUse[new Name($2, stackAttributes(#2)), $5, Stmt\Use_::TYPE_UNKNOWN]; }
|
||||
| T_USE T_NS_SEPARATOR namespace_name_parts T_NS_SEPARATOR '{' inline_use_declarations '}'
|
||||
{ $$ = Stmt\GroupUse[new Name($3, stackAttributes(#3)), $6, Stmt\Use_::TYPE_UNKNOWN]; }
|
||||
T_USE use_type legacy_namespace_name T_NS_SEPARATOR '{' unprefixed_use_declarations '}'
|
||||
{ $$ = Stmt\GroupUse[$3, $6, $2]; }
|
||||
| T_USE legacy_namespace_name T_NS_SEPARATOR '{' inline_use_declarations '}'
|
||||
{ $$ = Stmt\GroupUse[$2, $5, Stmt\Use_::TYPE_UNKNOWN]; }
|
||||
;
|
||||
|
||||
unprefixed_use_declarations:
|
||||
@ -154,8 +150,10 @@ unprefixed_use_declaration:
|
||||
;
|
||||
|
||||
use_declaration:
|
||||
unprefixed_use_declaration { $$ = $1; }
|
||||
| T_NS_SEPARATOR unprefixed_use_declaration { $$ = $2; }
|
||||
legacy_namespace_name
|
||||
{ $$ = Stmt\UseUse[$1, null, Stmt\Use_::TYPE_UNKNOWN]; $this->checkUseUse($$, #1); }
|
||||
| legacy_namespace_name T_AS identifier
|
||||
{ $$ = Stmt\UseUse[$1, $3, Stmt\Use_::TYPE_UNKNOWN]; $this->checkUseUse($$, #3); }
|
||||
;
|
||||
|
||||
inline_use_declaration:
|
||||
@ -826,9 +824,10 @@ class_name:
|
||||
;
|
||||
|
||||
name:
|
||||
namespace_name_parts { $$ = Name[$1]; }
|
||||
| T_NS_SEPARATOR namespace_name_parts { $$ = Name\FullyQualified[$2]; }
|
||||
| T_NAMESPACE T_NS_SEPARATOR namespace_name_parts { $$ = Name\Relative[$3]; }
|
||||
T_STRING { $$ = Name[$1]; }
|
||||
| T_NAME_QUALIFIED { $$ = Name[$1]; }
|
||||
| T_NAME_FULLY_QUALIFIED { $$ = Name\FullyQualified[substr($1, 1)]; }
|
||||
| T_NAME_RELATIVE { $$ = Name\Relative[substr($1, 10)]; }
|
||||
;
|
||||
|
||||
class_name_reference:
|
||||
|
@ -113,3 +113,6 @@
|
||||
%token T_DIR
|
||||
%token T_NS_SEPARATOR
|
||||
%token T_ELLIPSIS
|
||||
%token T_NAME_FULLY_QUALIFIED
|
||||
%token T_NAME_QUALIFIED
|
||||
%token T_NAME_RELATIVE
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -144,4 +144,7 @@ final class Tokens
|
||||
const T_DIR = 392;
|
||||
const T_NS_SEPARATOR = 393;
|
||||
const T_ELLIPSIS = 394;
|
||||
const T_NAME_FULLY_QUALIFIED = 395;
|
||||
const T_NAME_QUALIFIED = 396;
|
||||
const T_NAME_RELATIVE = 397;
|
||||
}
|
||||
|
@ -99,7 +99,7 @@ array(
|
||||
// Extra NS separator
|
||||
use Foo\{\Bar};
|
||||
-----
|
||||
Syntax error, unexpected T_NS_SEPARATOR, expecting T_STRING or T_FUNCTION or T_CONST from 3:10 to 3:10
|
||||
Syntax error, unexpected T_NAME_FULLY_QUALIFIED, expecting T_STRING or T_FUNCTION or T_CONST or T_NAME_QUALIFIED from 3:10 to 3:13
|
||||
array(
|
||||
0: Stmt_Expression(
|
||||
expr: Expr_ConstFetch(
|
||||
|
@ -32,7 +32,7 @@ array(
|
||||
-----
|
||||
<?php namespace static;
|
||||
-----
|
||||
Syntax error, unexpected T_STATIC, expecting T_STRING or T_NS_SEPARATOR or '{' from 1:17 to 1:22
|
||||
Syntax error, unexpected T_STATIC, expecting T_STRING or T_NAME_QUALIFIED or '{' from 1:17 to 1:22
|
||||
array(
|
||||
)
|
||||
-----
|
||||
|
Loading…
Reference in New Issue
Block a user