function ExpressionParser::getPrimary
3 calls to ExpressionParser::getPrimary()
- ExpressionParser::parseArguments in vendor/
twig/ twig/ src/ ExpressionParser.php - Parses arguments.
- ExpressionParser::parseExpression in vendor/
twig/ twig/ src/ ExpressionParser.php - ExpressionParser::parseTestExpression in vendor/
twig/ twig/ src/ ExpressionParser.php
File
-
vendor/
twig/ twig/ src/ ExpressionParser.php, line 235
Class
- ExpressionParser
- Parses expressions.
Namespace
TwigCode
private function getPrimary() : AbstractExpression {
$token = $this->parser
->getCurrentToken();
if ($this->isUnary($token)) {
$operator = $this->unaryOperators[$token->getValue()];
$this->parser
->getStream()
->next();
$expr = $this->parseExpression($operator['precedence']);
$class = $operator['class'];
$expr = new $class($expr, $token->getLine());
$expr->setAttribute('operator', 'unary_' . $token->getValue());
if ($this->deprecationCheck) {
$this->triggerPrecedenceDeprecations($expr);
}
return $this->parsePostfixExpression($expr);
}
elseif ($token->test(Token::PUNCTUATION_TYPE, '(')) {
$this->parser
->getStream()
->next();
$previous = $this->setDeprecationCheck(false);
try {
$expr = $this->parseExpression()
->setExplicitParentheses();
} finally {
$this->setDeprecationCheck($previous);
}
$this->parser
->getStream()
->expect(Token::PUNCTUATION_TYPE, ')', 'An opened parenthesis is not properly closed');
return $this->parsePostfixExpression($expr);
}
return $this->parsePrimaryExpression();
}