break;
case Twig_Token::NUMBER_TYPE:
- case Twig_Token::STRING_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;
+
default:
if ($token->test(Twig_Token::PUNCTUATION_TYPE, '[')) {
$node = $this->parseArrayExpression();
return $this->parsePostfixExpression($node);
}
+ public function parseStringExpression()
+ {
+ $stream = $this->parser->getStream();
+
+ $nodes = array();
+
+ while (true) {
+ if ($stream->test(Twig_Token::STRING_TYPE)) {
+ $token = $stream->next();
+ $nodes[] = new Twig_Node_Expression_Constant($token->getValue(), $token->getLine());
+ } else if ($stream->test(Twig_Token::INTERPOLATION_START_TYPE)) {
+ $stream->next();
+ $nodes[] = $this->parseExpression();
+ $stream->expect(Twig_Token::INTERPOLATION_END_TYPE);
+ } else {
+ break;
+ }
+ }
+
+ $expr = null;
+
+ foreach(array_reverse($nodes) as $node) {
+ if (null === $expr) {
+ $expr = $node;
+ } else {
+ $expr = new Twig_Node_Expression_Binary_Concat($node, $expr, $node->getLine());
+ }
+ }
+
+ return $expr;
+ }
+
public function parseArrayExpression()
{
$stream = $this->parser->getStream();