Skip to content

Commit a63b495

Browse files
committed
Migrate grammar to use PHP 8 T_NAME_* tokens
This will break everything on PHP < 8.
1 parent 2d19989 commit a63b495

File tree

8 files changed

+1792
-1800
lines changed

8 files changed

+1792
-1800
lines changed

grammar/php5.y

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,14 @@ reserved_non_modifiers_identifier:
4949
reserved_non_modifiers { $$ = Node\Identifier[$1]; }
5050
;
5151

52-
namespace_name_parts:
53-
T_STRING { init($1); }
54-
| namespace_name_parts T_NS_SEPARATOR T_STRING { push($1, $3); }
52+
namespace_name:
53+
T_STRING { $$ = Name[$1]; }
54+
| T_NAME_QUALIFIED { $$ = Name[$1]; }
5555
;
5656

57-
namespace_name:
58-
namespace_name_parts { $$ = Name[$1]; }
57+
legacy_namespace_name:
58+
namespace_name { $$ = $1; }
59+
| T_NAME_FULLY_QUALIFIED { $$ = Name[substr($1, 1)]; }
5960
;
6061

6162
plain_variable:
@@ -91,16 +92,11 @@ use_type:
9192
| T_CONST { $$ = Stmt\Use_::TYPE_CONSTANT; }
9293
;
9394

94-
/* Using namespace_name_parts here to avoid s/r conflict on T_NS_SEPARATOR */
9595
group_use_declaration:
96-
T_USE use_type namespace_name_parts T_NS_SEPARATOR '{' unprefixed_use_declarations '}'
97-
{ $$ = Stmt\GroupUse[new Name($3, stackAttributes(#3)), $6, $2]; }
98-
| T_USE use_type T_NS_SEPARATOR namespace_name_parts T_NS_SEPARATOR '{' unprefixed_use_declarations '}'
99-
{ $$ = Stmt\GroupUse[new Name($4, stackAttributes(#4)), $7, $2]; }
100-
| T_USE namespace_name_parts T_NS_SEPARATOR '{' inline_use_declarations '}'
101-
{ $$ = Stmt\GroupUse[new Name($2, stackAttributes(#2)), $5, Stmt\Use_::TYPE_UNKNOWN]; }
102-
| T_USE T_NS_SEPARATOR namespace_name_parts T_NS_SEPARATOR '{' inline_use_declarations '}'
103-
{ $$ = Stmt\GroupUse[new Name($3, stackAttributes(#3)), $6, Stmt\Use_::TYPE_UNKNOWN]; }
96+
T_USE use_type legacy_namespace_name T_NS_SEPARATOR '{' unprefixed_use_declarations '}'
97+
{ $$ = Stmt\GroupUse[$3, $6, $2]; }
98+
| T_USE legacy_namespace_name T_NS_SEPARATOR '{' inline_use_declarations '}'
99+
{ $$ = Stmt\GroupUse[$2, $5, Stmt\Use_::TYPE_UNKNOWN]; }
104100
;
105101

106102
unprefixed_use_declarations:
@@ -127,8 +123,10 @@ unprefixed_use_declaration:
127123
;
128124

129125
use_declaration:
130-
unprefixed_use_declaration { $$ = $1; }
131-
| T_NS_SEPARATOR unprefixed_use_declaration { $$ = $2; }
126+
legacy_namespace_name
127+
{ $$ = Stmt\UseUse[$1, null, Stmt\Use_::TYPE_UNKNOWN]; $this->checkUseUse($$, #1); }
128+
| legacy_namespace_name T_AS identifier
129+
{ $$ = Stmt\UseUse[$1, $3, Stmt\Use_::TYPE_UNKNOWN]; $this->checkUseUse($$, #3); }
132130
;
133131

134132
inline_use_declaration:
@@ -734,9 +732,10 @@ class_name:
734732
;
735733

736734
name:
737-
namespace_name_parts { $$ = Name[$1]; }
738-
| T_NS_SEPARATOR namespace_name_parts { $$ = Name\FullyQualified[$2]; }
739-
| T_NAMESPACE T_NS_SEPARATOR namespace_name_parts { $$ = Name\Relative[$3]; }
735+
T_STRING { $$ = Name[$1]; }
736+
| T_NAME_QUALIFIED { $$ = Name[$1]; }
737+
| T_NAME_FULLY_QUALIFIED { $$ = Name\FullyQualified[substr($1, 1)]; }
738+
| T_NAME_RELATIVE { $$ = Name\Relative[substr($1, 10)]; }
740739
;
741740

742741
class_name_reference:

grammar/php7.y

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,14 @@ reserved_non_modifiers_identifier:
4949
reserved_non_modifiers { $$ = Node\Identifier[$1]; }
5050
;
5151

52-
namespace_name_parts:
53-
T_STRING { init($1); }
54-
| namespace_name_parts T_NS_SEPARATOR T_STRING { push($1, $3); }
52+
namespace_name:
53+
T_STRING { $$ = Name[$1]; }
54+
| T_NAME_QUALIFIED { $$ = Name[$1]; }
5555
;
5656

57-
namespace_name:
58-
namespace_name_parts { $$ = Name[$1]; }
57+
legacy_namespace_name:
58+
namespace_name { $$ = $1; }
59+
| T_NAME_FULLY_QUALIFIED { $$ = Name[substr($1, 1)]; }
5960
;
6061

6162
plain_variable:
@@ -105,16 +106,11 @@ use_type:
105106
| T_CONST { $$ = Stmt\Use_::TYPE_CONSTANT; }
106107
;
107108

108-
/* Using namespace_name_parts here to avoid s/r conflict on T_NS_SEPARATOR */
109109
group_use_declaration:
110-
T_USE use_type namespace_name_parts T_NS_SEPARATOR '{' unprefixed_use_declarations '}'
111-
{ $$ = Stmt\GroupUse[new Name($3, stackAttributes(#3)), $6, $2]; }
112-
| T_USE use_type T_NS_SEPARATOR namespace_name_parts T_NS_SEPARATOR '{' unprefixed_use_declarations '}'
113-
{ $$ = Stmt\GroupUse[new Name($4, stackAttributes(#4)), $7, $2]; }
114-
| T_USE namespace_name_parts T_NS_SEPARATOR '{' inline_use_declarations '}'
115-
{ $$ = Stmt\GroupUse[new Name($2, stackAttributes(#2)), $5, Stmt\Use_::TYPE_UNKNOWN]; }
116-
| T_USE T_NS_SEPARATOR namespace_name_parts T_NS_SEPARATOR '{' inline_use_declarations '}'
117-
{ $$ = Stmt\GroupUse[new Name($3, stackAttributes(#3)), $6, Stmt\Use_::TYPE_UNKNOWN]; }
110+
T_USE use_type legacy_namespace_name T_NS_SEPARATOR '{' unprefixed_use_declarations '}'
111+
{ $$ = Stmt\GroupUse[$3, $6, $2]; }
112+
| T_USE legacy_namespace_name T_NS_SEPARATOR '{' inline_use_declarations '}'
113+
{ $$ = Stmt\GroupUse[$2, $5, Stmt\Use_::TYPE_UNKNOWN]; }
118114
;
119115

120116
unprefixed_use_declarations:
@@ -154,8 +150,10 @@ unprefixed_use_declaration:
154150
;
155151

156152
use_declaration:
157-
unprefixed_use_declaration { $$ = $1; }
158-
| T_NS_SEPARATOR unprefixed_use_declaration { $$ = $2; }
153+
legacy_namespace_name
154+
{ $$ = Stmt\UseUse[$1, null, Stmt\Use_::TYPE_UNKNOWN]; $this->checkUseUse($$, #1); }
155+
| legacy_namespace_name T_AS identifier
156+
{ $$ = Stmt\UseUse[$1, $3, Stmt\Use_::TYPE_UNKNOWN]; $this->checkUseUse($$, #3); }
159157
;
160158

161159
inline_use_declaration:
@@ -826,9 +824,10 @@ class_name:
826824
;
827825

828826
name:
829-
namespace_name_parts { $$ = Name[$1]; }
830-
| T_NS_SEPARATOR namespace_name_parts { $$ = Name\FullyQualified[$2]; }
831-
| T_NAMESPACE T_NS_SEPARATOR namespace_name_parts { $$ = Name\Relative[$3]; }
827+
T_STRING { $$ = Name[$1]; }
828+
| T_NAME_QUALIFIED { $$ = Name[$1]; }
829+
| T_NAME_FULLY_QUALIFIED { $$ = Name\FullyQualified[substr($1, 1)]; }
830+
| T_NAME_RELATIVE { $$ = Name\Relative[substr($1, 10)]; }
832831
;
833832

834833
class_name_reference:

grammar/tokens.y

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,6 @@
113113
%token T_DIR
114114
%token T_NS_SEPARATOR
115115
%token T_ELLIPSIS
116+
%token T_NAME_FULLY_QUALIFIED
117+
%token T_NAME_QUALIFIED
118+
%token T_NAME_RELATIVE

0 commit comments

Comments
 (0)