protected function parsePrimaryExpression()
{
$token = $this->stream->getCurrentToken();
switch ($token->getType()) {
case Token::CONSTANT:
case Token::NUMBER:
case Token::STRING:
$node = $this->parseLiteralExpression();
break;
case Token::NAME:
$this->stream->next();
$node = new Expression\NameExpression($token->getValue(), $token->getLine());
if ($this->stream->test(Token::OPERATOR, '(')) {
$node = $this->parseFunctionCallExpression($node);
}
break;
case Token::CONSTANT:
case Token::OPERATOR:
if (($name = $this->parseName(false)) !== null) {
$node = new Expression\NameExpression($name->getValue(), $token->getLine());
break;
}
default:
if ($this->stream->consume(Token::OPERATOR, '@')) {
$node = new Expression\FilterExpression($this->parseMacroExpression($token), array('raw'), false, $token->getLine());
} elseif ($this->stream->consume(Token::OPERATOR, '[')) {
$node = $this->parseArrayExpression();
$this->stream->expect(Token::OPERATOR, ']');
} elseif ($this->stream->consume(Token::OPERATOR, '(')) {
$node = $this->parseExpression();
$this->stream->expect(Token::OPERATOR, ')');
} else {
throw new SyntaxError(sprintf('unexpected "%s", expecting an expression', str_replace("\n", '\\n', $token->getValue())), $token);
}
}
return $this->parsePostfixExpression($node);
}