Skip to content

Commit

Permalink
Merge pull request #287 from pdepend/GH285-unexpected-token-t_trait_c
Browse files Browse the repository at this point in the history
Closes #285: Parse the magic constant __TRAIT__
  • Loading branch information
Manuel Pichler committed Jan 6, 2017
2 parents e805725 + b76e2b0 commit d644a7b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
Expand Up @@ -4424,11 +4424,14 @@ protected function parseConstant()
case Tokens::T_FUNC_C:
case Tokens::T_CLASS_C:
case Tokens::T_METHOD_C:
case Tokens::T_TRAIT_C:
$token = $this->consumeToken($type);
$const = $this->builder->buildAstConstant($token->image);

return $this->setNodePositionsAndReturn(
$this->builder->buildAstConstant($token->image)
);
break;
}
return $this->setNodePositionsAndReturn($const);
}

/**
Expand Down
13 changes: 13 additions & 0 deletions src/main/php/PDepend/Source/Language/PHP/PHPParserVersion54.php
Expand Up @@ -262,4 +262,17 @@ protected function parsePostfixIdentifier()
}
return $this->parseOptionalIndexExpression($node);
}

/**
* @return \PDepend\Source\AST\ASTNode
*/
protected function parseOptionalExpressionForVersion()
{
switch ($this->tokenizer->peek()) {
case Tokens::T_TRAIT_C:
return $this->parseConstant();
default:
return parent::parseOptionalExpressionForVersion();
}
}
}
Expand Up @@ -382,6 +382,14 @@ public function testListKeywordAsFunctionNameThrowsException()
$this->parseCodeResourceForTest();
}

/**
* @return void
*/
public function testMagicTraitConstantInString()
{
$this->assertNotNull($this->parseCodeResourceForTest());
}

/**
* @param \PDepend\Source\Tokenizer\Tokenizer $tokenizer
* @param \PDepend\Source\Builder\Builder $builder
Expand Down
@@ -0,0 +1,6 @@
<?php
class UnexpectedTokenTrait {
public function foo() {
throw new \LogicException('Not implemented ' . __TRAIT__);
}
}

0 comments on commit d644a7b

Please sign in to comment.