You are here

public function Twig_ExpressionParser::parsePrimaryExpression in Translation template extractor 6.3

Same name and namespace in other branches
  1. 7.3 vendor/Twig/ExpressionParser.php \Twig_ExpressionParser::parsePrimaryExpression()
2 calls to Twig_ExpressionParser::parsePrimaryExpression()
Twig_ExpressionParser::getPrimary in vendor/Twig/ExpressionParser.php
Twig_ExpressionParser::parseArguments in vendor/Twig/ExpressionParser.php
Parses arguments.

File

vendor/Twig/ExpressionParser.php, line 118

Class

Twig_ExpressionParser
Parses expressions.

Code

public function parsePrimaryExpression() {
  $token = $this->parser
    ->getCurrentToken();
  switch ($token
    ->getType()) {
    case Twig_Token::NAME_TYPE:
      $this->parser
        ->getStream()
        ->next();
      switch ($token
        ->getValue()) {
        case 'true':
        case 'TRUE':
          $node = new Twig_Node_Expression_Constant(true, $token
            ->getLine());
          break;
        case 'false':
        case 'FALSE':
          $node = new Twig_Node_Expression_Constant(false, $token
            ->getLine());
          break;
        case 'none':
        case 'NONE':
        case 'null':
        case 'NULL':
          $node = new Twig_Node_Expression_Constant(null, $token
            ->getLine());
          break;
        default:
          if ('(' === $this->parser
            ->getCurrentToken()
            ->getValue()) {
            $node = $this
              ->getFunctionNode($token
              ->getValue(), $token
              ->getLine());
          }
          else {
            $node = new Twig_Node_Expression_Name($token
              ->getValue(), $token
              ->getLine());
          }
      }
      break;
    case Twig_Token::NUMBER_TYPE:
      $this->parser
        ->getStream()
        ->next();
      $node = new Twig_Node_Expression_Constant($token
        ->getValue(), $token
        ->getLine());
      break;
    case Twig_Token::STRING_TYPE:
    case Twig_Token::INTERPOLATION_START_TYPE:
      $node = $this
        ->parseStringExpression();
      break;
    case Twig_Token::OPERATOR_TYPE:
      if (preg_match(Twig_Lexer::REGEX_NAME, $token
        ->getValue(), $matches) && $matches[0] == $token
        ->getValue()) {

        // in this context, string operators are variable names
        $this->parser
          ->getStream()
          ->next();
        $node = new Twig_Node_Expression_Name($token
          ->getValue(), $token
          ->getLine());
        break;
      }
    default:
      if ($token
        ->test(Twig_Token::PUNCTUATION_TYPE, '[')) {
        $node = $this
          ->parseArrayExpression();
      }
      elseif ($token
        ->test(Twig_Token::PUNCTUATION_TYPE, '{')) {
        $node = $this
          ->parseHashExpression();
      }
      else {
        throw new Twig_Error_Syntax(sprintf('Unexpected token "%s" of value "%s"', Twig_Token::typeToEnglish($token
          ->getType()), $token
          ->getValue()), $token
          ->getLine(), $this->parser
          ->getFilename());
      }
  }
  return $this
    ->parsePostfixExpression($node);
}