Permalink
Browse files

Closes #285: Parse the magic constant __TRAIT__

  • Loading branch information...
manuelpichler committed Jan 6, 2017
1 parent e805725 commit b76e2b09cadc16c548990c2e95ea11ddf80ab962
@@ -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);
}
/**
@@ -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();
}
}
}
@@ -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
@@ -0,0 +1,6 @@
<?php
class UnexpectedTokenTrait {
public function foo() {
throw new \LogicException('Not implemented ' . __TRAIT__);
}
}

0 comments on commit b76e2b0

Please sign in to comment.