Skip to content

Commit 6a4ecd0

Browse files
committed
Fix #65 consecutive interpolations
split: e04da2db91dd4eb9b08396831a3e02cd880e0424
1 parent ed31f55 commit 6a4ecd0

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

Parser/State.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,13 +462,23 @@ public function nextToken()
462462
*
463463
* @see \Generator->current
464464
*
465-
* @return array the token array (always _one_ token, as an array)
465+
* @return TokenInterface|null
466466
*/
467467
public function getToken()
468468
{
469469
return $this->tokens->current();
470470
}
471471

472+
/**
473+
* Return the token parsed just before the current one (->getToken()).
474+
*
475+
* @return TokenInterface|null
476+
*/
477+
public function getPreviousToken()
478+
{
479+
return $this->parser->getLexer()->getPreviousToken();
480+
}
481+
472482
public function is(Node $node, array $classNames)
473483
{
474484
foreach ($classNames as $className) {

Parser/TokenHandler/InterpolationStartTokenHandler.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ public function handleToken(TokenInterface $token, State $state)
2424
}
2525

2626
$node = $state->getCurrentNode();
27-
if (!$node) {
27+
28+
if (!$node && !($state->getPreviousToken() instanceof InterpolationEndToken)) {
2829
/** @var ElementNode $element */
2930
$element = $state->createNode(ElementNode::class, $token);
3031
$state->setCurrentNode($element);
@@ -48,13 +49,15 @@ public function handleToken(TokenInterface $token, State $state)
4849

4950
return;
5051
}
52+
5153
if ($state->currentNodeIs([
5254
TextNode::class,
5355
CodeNode::class,
5456
ExpressionNode::class,
5557
])) {
5658
$node = $node->getParent();
5759
}
60+
5861
$state->getInterpolationStack()->attach($token->getEnd(), (object) [
5962
'currentNode' => $node,
6063
'parentNode' => $state->getParentNode(),

0 commit comments

Comments
 (0)