You are here

protected function Twig_ExpressionParser::getPrimary in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/twig/twig/lib/Twig/ExpressionParser.php \Twig_ExpressionParser::getPrimary()
1 call to Twig_ExpressionParser::getPrimary()
Twig_ExpressionParser::parseExpression in vendor/twig/twig/lib/Twig/ExpressionParser.php

File

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();
}