Permalink
Browse files

Close #281: Internal parser state issue fixed.

  • Loading branch information...
manuelpichler committed Jan 6, 2017
1 parent b5d708e commit 00a61c6a1c0ad6c5f440c22e20491573ba571719
@@ -218,7 +218,7 @@
*
* @var \PDepend\Source\AST\AbstractASTClassOrInterface
*/
private $classOrInterface;
protected $classOrInterface;
/**
* If this property is set to <b>true</b> the parser will ignore all doc
@@ -216,55 +216,58 @@ protected function parseAllocationExpressionTypeReference(ASTAllocationExpressio
protected function parseAnonymousClassDeclaration(ASTAllocationExpression $allocation)
{
$this->consumeComments();
if (Tokens::T_CLASS !== $this->tokenizer->peek()) {
return null;
}
switch ($this->tokenizer->peek()) {
case Tokens::T_CLASS:
$this->tokenStack->push();
$this->consumeToken(Tokens::T_CLASS);
$this->consumeComments();
$class = $this->builder->buildAnonymousClass();
$class->setName(
sprintf(
'class@anonymous%s0x%s',
$this->compilationUnit->getFileName(),
uniqid('')
)
);
$class->setCompilationUnit($this->compilationUnit);
$class->setUserDefined();
$classOrInterface = $this->classOrInterface;
if ($this->isNextTokenArguments()) {
$class->addChild($this->parseArguments());
}
$this->tokenStack->push();
$this->consumeComments();
$tokenType = $this->tokenizer->peek();
$this->consumeToken(Tokens::T_CLASS);
$this->consumeComments();
if ($tokenType === Tokens::T_EXTENDS) {
$class = $this->parseClassExtends($class);
$class = $this->builder->buildAnonymousClass();
$class->setName(
sprintf(
'class@anonymous%s0x%s',
$this->compilationUnit->getFileName(),
uniqid('')
)
);
$class->setCompilationUnit($this->compilationUnit);
$class->setUserDefined();
if ($this->isNextTokenArguments()) {
$class->addChild($this->parseArguments());
}
$this->consumeComments();
$tokenType = $this->tokenizer->peek();
}
$this->consumeComments();
$tokenType = $this->tokenizer->peek();
if ($tokenType === Tokens::T_IMPLEMENTS) {
$this->consumeToken(Tokens::T_IMPLEMENTS);
$this->parseInterfaceList($class);
}
if ($tokenType === Tokens::T_EXTENDS) {
$class = $this->parseClassExtends($class);
$allocation->addChild(
$this->setNodePositionsAndReturn(
$this->parseTypeBody($class),
$tokens
)
);
$class->setTokens($tokens);
$this->consumeComments();
$tokenType = $this->tokenizer->peek();
}
return $allocation;
if ($tokenType === Tokens::T_IMPLEMENTS) {
$this->consumeToken(Tokens::T_IMPLEMENTS);
$this->parseInterfaceList($class);
}
return null;
$allocation->addChild(
$this->setNodePositionsAndReturn(
$this->parseTypeBody($class),
$tokens
)
);
$class->setTokens($tokens);
$this->classOrInterface = $classOrInterface;
return $allocation;
}
/**

0 comments on commit 00a61c6

Please sign in to comment.