private function parseNamespaceDeclaration()
{
// Consume namespace keyword and strip optional comments
$this->consumeToken(Tokens::T_NAMESPACE);
$this->consumeComments();
$tokenType = $this->tokenizer->peek();
// Search for a namespace identifier
if ($this->isClassName($tokenType)) {
// Reset namespace property
$this->namespaceName = null;
$qualifiedName = $this->parseQualifiedName();
$this->consumeComments();
if ($this->tokenizer->peek() === Tokens::T_CURLY_BRACE_OPEN) {
$this->consumeToken(Tokens::T_CURLY_BRACE_OPEN);
} else {
$this->consumeToken(Tokens::T_SEMICOLON);
}
// Create a package for this namespace
$this->namespaceName = $qualifiedName;
$this->useSymbolTable->resetScope();
} elseif ($tokenType === Tokens::T_BACKSLASH) {
// Same namespace reference, something like:
// new namespace\Foo();
// or:
// $x = namespace\foo::bar();
// Now parse a qualified name
$this->parseQualifiedNameRaw();
} else {
// Consume opening curly brace
$this->consumeToken(Tokens::T_CURLY_BRACE_OPEN);
// Create a package for this namespace
$this->namespaceName = '';
$this->useSymbolTable->resetScope();
}
$this->reset();
}