You are here

public function Twig_ExpressionParser::parseStringExpression in Translation template extractor 6.3

Same name and namespace in other branches
  1. 7.3 vendor/Twig/ExpressionParser.php \Twig_ExpressionParser::parseStringExpression()
1 call to Twig_ExpressionParser::parseStringExpression()
Twig_ExpressionParser::parsePrimaryExpression in vendor/Twig/ExpressionParser.php

File

vendor/Twig/ExpressionParser.php, line 182

Class

Twig_ExpressionParser
Parses expressions.

Code

public function parseStringExpression() {
  $stream = $this->parser
    ->getStream();
  $nodes = array();

  // a string cannot be followed by another string in a single expression
  $nextCanBeString = true;
  while (true) {
    if ($nextCanBeString && ($token = $stream
      ->nextIf(Twig_Token::STRING_TYPE))) {
      $nodes[] = new Twig_Node_Expression_Constant($token
        ->getValue(), $token
        ->getLine());
      $nextCanBeString = false;
    }
    elseif ($stream
      ->nextIf(Twig_Token::INTERPOLATION_START_TYPE)) {
      $nodes[] = $this
        ->parseExpression();
      $stream
        ->expect(Twig_Token::INTERPOLATION_END_TYPE);
      $nextCanBeString = true;
    }
    else {
      break;
    }
  }
  $expr = array_shift($nodes);
  foreach ($nodes as $node) {
    $expr = new Twig_Node_Expression_Binary_Concat($expr, $node, $node
      ->getLine());
  }
  return $expr;
}