Skip to content

Commit

Permalink
Close #281: Internal parser state issue fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
Manuel Pichler committed Jan 6, 2017
1 parent b5d708e commit 00a61c6
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 41 deletions.
Expand Up @@ -218,7 +218,7 @@ abstract class AbstractPHPParser
*
* @var \PDepend\Source\AST\AbstractASTClassOrInterface
*/
private $classOrInterface;
protected $classOrInterface;

/**
* If this property is set to <b>true</b> the parser will ignore all doc
Expand Down
83 changes: 43 additions & 40 deletions src/main/php/PDepend/Source/Language/PHP/PHPParserVersion70.php
Expand Up @@ -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;
}

/**
Expand Down

0 comments on commit 00a61c6

Please sign in to comment.