Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ExpressionParser.php

function ExpressionParser::parseStringExpression

1 call to ExpressionParser::parseStringExpression()
ExpressionParser::parsePrimaryExpression in vendor/twig/twig/src/ExpressionParser.php

File

vendor/twig/twig/src/ExpressionParser.php, line 374

Class

ExpressionParser
Parses expressions.

Namespace

Twig

Code

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

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal