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
TwigCode
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;
}