protected function Twig_ExpressionParser::getPrimary

1 call to Twig_ExpressionParser::getPrimary()
Twig_ExpressionParser::parseExpression in drupal/core/vendor/twig/twig/lib/Twig/ExpressionParser.php

File

drupal/core/vendor/twig/twig/lib/Twig/ExpressionParser.php, line 65

Class

Twig_ExpressionParser
Parses expressions.

Code

protected function getPrimary() {
  $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'];
    return $this
      ->parsePostfixExpression(new $class($expr, $token
      ->getLine()));
  }
  elseif ($token
    ->test(Twig_Token::PUNCTUATION_TYPE, '(')) {
    $this->parser
      ->getStream()
      ->next();
    $expr = $this
      ->parseExpression();
    $this->parser
      ->getStream()
      ->expect(Twig_Token::PUNCTUATION_TYPE, ')', 'An opened parenthesis is not properly closed');
    return $this
      ->parsePostfixExpression($expr);
  }
  return $this
    ->parsePrimaryExpression();
}