Allow keywords in namespace declaration

This commit is contained in:
Nikita Popov 2020-08-09 21:19:59 +02:00
parent 3aadc15e2e
commit 78e08fc178
4 changed files with 1249 additions and 1212 deletions

View File

@ -49,6 +49,12 @@ reserved_non_modifiers_identifier:
reserved_non_modifiers { $$ = Node\Identifier[$1]; }
;
namespace_declaration_name:
T_STRING { $$ = Name[$1]; }
| semi_reserved { $$ = Name[$1]; }
| T_NAME_QUALIFIED { $$ = Name[$1]; }
;
namespace_name:
T_STRING { $$ = Name[$1]; }
| T_NAME_QUALIFIED { $$ = Name[$1]; }
@ -83,11 +89,11 @@ top_statement:
| class_declaration_statement { $$ = $1; }
| T_HALT_COMPILER
{ $$ = Stmt\HaltCompiler[$this->lexer->handleHaltCompiler()]; }
| T_NAMESPACE namespace_name semi
| T_NAMESPACE namespace_declaration_name semi
{ $$ = Stmt\Namespace_[$2, null];
$$->setAttribute('kind', Stmt\Namespace_::KIND_SEMICOLON);
$this->checkNamespace($$); }
| T_NAMESPACE namespace_name '{' top_statement_list '}'
| T_NAMESPACE namespace_declaration_name '{' top_statement_list '}'
{ $$ = Stmt\Namespace_[$2, $4];
$$->setAttribute('kind', Stmt\Namespace_::KIND_BRACED);
$this->checkNamespace($$); }

File diff suppressed because it is too large Load Diff

View File

@ -1,44 +1,66 @@
Keywords in namespaced name
-----
<?php
namespace fn;
namespace fn\use;
fn\use();
\fn\use();
namespace\fn\use();
-----
!!php7
array(
0: Stmt_Expression(
expr: Expr_FuncCall(
name: Name(
parts: array(
0: fn
1: use
)
)
args: array(
0: Stmt_Namespace(
name: Name(
parts: array(
0: fn
)
)
)
1: Stmt_Expression(
expr: Expr_FuncCall(
name: Name_FullyQualified(
parts: array(
0: fn
1: use
)
)
args: array(
)
stmts: array(
)
)
2: Stmt_Expression(
expr: Expr_FuncCall(
name: Name_Relative(
parts: array(
0: fn
1: use
1: Stmt_Namespace(
name: Name(
parts: array(
0: fn
1: use
)
)
stmts: array(
0: Stmt_Expression(
expr: Expr_FuncCall(
name: Name(
parts: array(
0: fn
1: use
)
)
args: array(
)
)
)
args: array(
1: Stmt_Expression(
expr: Expr_FuncCall(
name: Name_FullyQualified(
parts: array(
0: fn
1: use
)
)
args: array(
)
)
)
2: Stmt_Expression(
expr: Expr_FuncCall(
name: Name_Relative(
parts: array(
0: fn
1: use
)
)
args: array(
)
)
)
)
)

View File

@ -32,8 +32,18 @@ array(
-----
<?php namespace static;
-----
Syntax error, unexpected T_STATIC, expecting T_STRING or T_NAME_QUALIFIED or '{' from 1:17 to 1:22
!!php7
Cannot use 'static' as namespace name from 1:17 to 1:22
array(
0: Stmt_Namespace(
name: Name(
parts: array(
0: static
)
)
stmts: array(
)
)
)
-----
<?php use A as self;