mirror of
https://github.com/danog/PHP-Parser.git
synced 2025-01-22 05:41:23 +01:00
Add attribute for namespace kinds (#417)
One of KIND_SEMICOLON or KIND_BRACED.
This commit is contained in:
parent
a1e8e1a30e
commit
5a9fbca54a
@ -1,7 +1,10 @@
|
||||
Version 3.1.2-dev
|
||||
-----------------
|
||||
|
||||
Nothing yet.
|
||||
### Added
|
||||
|
||||
* Added `kind` attribute for `Stmt\Namespace_` node, which is one of `KIND_SEMICOLON` or
|
||||
`KIND_BRACED`. (#417)
|
||||
|
||||
Version 3.1.1 (2017-09-02)
|
||||
--------------------------
|
||||
|
@ -56,11 +56,17 @@ top_statement:
|
||||
| T_HALT_COMPILER
|
||||
{ $$ = Stmt\HaltCompiler[$this->lexer->handleHaltCompiler()]; }
|
||||
| T_NAMESPACE namespace_name ';'
|
||||
{ $$ = Stmt\Namespace_[$2, null]; $this->checkNamespace($$); }
|
||||
{ $$ = Stmt\Namespace_[$2, null];
|
||||
$$->setAttribute('kind', Stmt\Namespace_::KIND_SEMICOLON);
|
||||
$this->checkNamespace($$); }
|
||||
| T_NAMESPACE namespace_name '{' top_statement_list '}'
|
||||
{ $$ = Stmt\Namespace_[$2, $4]; $this->checkNamespace($$); }
|
||||
{ $$ = Stmt\Namespace_[$2, $4];
|
||||
$$->setAttribute('kind', Stmt\Namespace_::KIND_BRACED);
|
||||
$this->checkNamespace($$); }
|
||||
| T_NAMESPACE '{' top_statement_list '}'
|
||||
{ $$ = Stmt\Namespace_[null, $3]; $this->checkNamespace($$); }
|
||||
{ $$ = Stmt\Namespace_[null, $3];
|
||||
$$->setAttribute('kind', Stmt\Namespace_::KIND_BRACED);
|
||||
$this->checkNamespace($$); }
|
||||
| T_USE use_declarations ';' { $$ = Stmt\Use_[$2, Stmt\Use_::TYPE_NORMAL]; }
|
||||
| T_USE use_type use_declarations ';' { $$ = Stmt\Use_[$3, $2]; }
|
||||
| group_use_declaration ';' { $$ = $1; }
|
||||
|
@ -70,11 +70,17 @@ top_statement:
|
||||
| T_HALT_COMPILER
|
||||
{ $$ = Stmt\HaltCompiler[$this->lexer->handleHaltCompiler()]; }
|
||||
| T_NAMESPACE namespace_name semi
|
||||
{ $$ = Stmt\Namespace_[$2, null]; $this->checkNamespace($$); }
|
||||
{ $$ = Stmt\Namespace_[$2, null];
|
||||
$$->setAttribute('kind', Stmt\Namespace_::KIND_SEMICOLON);
|
||||
$this->checkNamespace($$); }
|
||||
| T_NAMESPACE namespace_name '{' top_statement_list '}'
|
||||
{ $$ = Stmt\Namespace_[$2, $4]; $this->checkNamespace($$); }
|
||||
{ $$ = Stmt\Namespace_[$2, $4];
|
||||
$$->setAttribute('kind', Stmt\Namespace_::KIND_BRACED);
|
||||
$this->checkNamespace($$); }
|
||||
| T_NAMESPACE '{' top_statement_list '}'
|
||||
{ $$ = Stmt\Namespace_[null, $3]; $this->checkNamespace($$); }
|
||||
{ $$ = Stmt\Namespace_[null, $3];
|
||||
$$->setAttribute('kind', Stmt\Namespace_::KIND_BRACED);
|
||||
$this->checkNamespace($$); }
|
||||
| T_USE use_declarations semi { $$ = Stmt\Use_[$2, Stmt\Use_::TYPE_NORMAL]; }
|
||||
| T_USE use_type use_declarations semi { $$ = Stmt\Use_[$3, $2]; }
|
||||
| group_use_declaration semi { $$ = $1; }
|
||||
|
@ -6,6 +6,10 @@ use PhpParser\Node;
|
||||
|
||||
class Namespace_ extends Node\Stmt
|
||||
{
|
||||
/* For use in the "kind" attribute */
|
||||
const KIND_SEMICOLON = 1;
|
||||
const KIND_BRACED = 2;
|
||||
|
||||
/** @var null|Node\Name Name */
|
||||
public $name;
|
||||
/** @var Node[] Statements */
|
||||
|
@ -1257,15 +1257,21 @@ class Php5 extends \PhpParser\ParserAbstract
|
||||
}
|
||||
|
||||
protected function reduceRule89() {
|
||||
$this->semValue = new Stmt\Namespace_($this->semStack[$this->stackPos-(3-2)], null, $this->startAttributeStack[$this->stackPos-(3-1)] + $this->endAttributes); $this->checkNamespace($this->semValue);
|
||||
$this->semValue = new Stmt\Namespace_($this->semStack[$this->stackPos-(3-2)], null, $this->startAttributeStack[$this->stackPos-(3-1)] + $this->endAttributes);
|
||||
$this->semValue->setAttribute('kind', Stmt\Namespace_::KIND_SEMICOLON);
|
||||
$this->checkNamespace($this->semValue);
|
||||
}
|
||||
|
||||
protected function reduceRule90() {
|
||||
$this->semValue = new Stmt\Namespace_($this->semStack[$this->stackPos-(5-2)], $this->semStack[$this->stackPos-(5-4)], $this->startAttributeStack[$this->stackPos-(5-1)] + $this->endAttributes); $this->checkNamespace($this->semValue);
|
||||
$this->semValue = new Stmt\Namespace_($this->semStack[$this->stackPos-(5-2)], $this->semStack[$this->stackPos-(5-4)], $this->startAttributeStack[$this->stackPos-(5-1)] + $this->endAttributes);
|
||||
$this->semValue->setAttribute('kind', Stmt\Namespace_::KIND_BRACED);
|
||||
$this->checkNamespace($this->semValue);
|
||||
}
|
||||
|
||||
protected function reduceRule91() {
|
||||
$this->semValue = new Stmt\Namespace_(null, $this->semStack[$this->stackPos-(4-3)], $this->startAttributeStack[$this->stackPos-(4-1)] + $this->endAttributes); $this->checkNamespace($this->semValue);
|
||||
$this->semValue = new Stmt\Namespace_(null, $this->semStack[$this->stackPos-(4-3)], $this->startAttributeStack[$this->stackPos-(4-1)] + $this->endAttributes);
|
||||
$this->semValue->setAttribute('kind', Stmt\Namespace_::KIND_BRACED);
|
||||
$this->checkNamespace($this->semValue);
|
||||
}
|
||||
|
||||
protected function reduceRule92() {
|
||||
|
@ -1191,15 +1191,21 @@ class Php7 extends \PhpParser\ParserAbstract
|
||||
}
|
||||
|
||||
protected function reduceRule95() {
|
||||
$this->semValue = new Stmt\Namespace_($this->semStack[$this->stackPos-(3-2)], null, $this->startAttributeStack[$this->stackPos-(3-1)] + $this->endAttributes); $this->checkNamespace($this->semValue);
|
||||
$this->semValue = new Stmt\Namespace_($this->semStack[$this->stackPos-(3-2)], null, $this->startAttributeStack[$this->stackPos-(3-1)] + $this->endAttributes);
|
||||
$this->semValue->setAttribute('kind', Stmt\Namespace_::KIND_SEMICOLON);
|
||||
$this->checkNamespace($this->semValue);
|
||||
}
|
||||
|
||||
protected function reduceRule96() {
|
||||
$this->semValue = new Stmt\Namespace_($this->semStack[$this->stackPos-(5-2)], $this->semStack[$this->stackPos-(5-4)], $this->startAttributeStack[$this->stackPos-(5-1)] + $this->endAttributes); $this->checkNamespace($this->semValue);
|
||||
$this->semValue = new Stmt\Namespace_($this->semStack[$this->stackPos-(5-2)], $this->semStack[$this->stackPos-(5-4)], $this->startAttributeStack[$this->stackPos-(5-1)] + $this->endAttributes);
|
||||
$this->semValue->setAttribute('kind', Stmt\Namespace_::KIND_BRACED);
|
||||
$this->checkNamespace($this->semValue);
|
||||
}
|
||||
|
||||
protected function reduceRule97() {
|
||||
$this->semValue = new Stmt\Namespace_(null, $this->semStack[$this->stackPos-(4-3)], $this->startAttributeStack[$this->stackPos-(4-1)] + $this->endAttributes); $this->checkNamespace($this->semValue);
|
||||
$this->semValue = new Stmt\Namespace_(null, $this->semStack[$this->stackPos-(4-3)], $this->startAttributeStack[$this->stackPos-(4-1)] + $this->endAttributes);
|
||||
$this->semValue->setAttribute('kind', Stmt\Namespace_::KIND_BRACED);
|
||||
$this->checkNamespace($this->semValue);
|
||||
}
|
||||
|
||||
protected function reduceRule98() {
|
||||
|
@ -169,6 +169,9 @@ EOC;
|
||||
array("exit(1)", ['kind' => Expr\Exit_::KIND_EXIT]),
|
||||
array("?>Foo", ['hasLeadingNewline' => false]),
|
||||
array("?>\nFoo", ['hasLeadingNewline' => true]),
|
||||
array("namespace Foo;", ['kind' => Node\Stmt\Namespace_::KIND_SEMICOLON]),
|
||||
array("namespace Foo {}", ['kind' => Node\Stmt\Namespace_::KIND_BRACED]),
|
||||
array("namespace {}", ['kind' => Node\Stmt\Namespace_::KIND_BRACED]),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user