|
23 | 23 | use Twig\Token; |
24 | 24 | use Twig\TokenParser\AbstractTokenParser; |
25 | 25 |
|
| 26 | +use function method_exists; |
| 27 | + |
26 | 28 | class TransTokenParser extends AbstractTokenParser |
27 | 29 | { |
28 | 30 | /** |
@@ -57,18 +59,24 @@ protected function preParse(Token $token): array |
57 | 59 | /* If we aren't closing the block, do we have a domain? */ |
58 | 60 | if ($stream->test(Token::NAME_TYPE)) { |
59 | 61 | $stream->expect(Token::NAME_TYPE, 'from'); |
60 | | - $domain = $this->parser->parseExpression(); |
| 62 | + $domain = method_exists($this->parser, 'parseExpression') |
| 63 | + ? $this->parser->parseExpression() |
| 64 | + : $this->parser->getExpressionParser()->parseExpression(); |
61 | 65 | } |
62 | 66 |
|
63 | 67 | if (! $stream->test(Token::BLOCK_END_TYPE)) { |
64 | | - $body = $this->parser->parseExpression(); |
| 68 | + $body = method_exists($this->parser, 'parseExpression') |
| 69 | + ? $this->parser->parseExpression() |
| 70 | + : $this->parser->getExpressionParser()->parseExpression(); |
65 | 71 | } else { |
66 | 72 | $stream->expect(Token::BLOCK_END_TYPE); |
67 | 73 | $body = $this->parser->subparse([$this, 'decideForFork']); |
68 | 74 | $next = $stream->next()->getValue(); |
69 | 75 |
|
70 | 76 | if ($next === 'plural') { |
71 | | - $count = $this->parser->parseExpression(); |
| 77 | + $count = method_exists($this->parser, 'parseExpression') |
| 78 | + ? $this->parser->parseExpression() |
| 79 | + : $this->parser->getExpressionParser()->parseExpression(); |
72 | 80 | $stream->expect(Token::BLOCK_END_TYPE); |
73 | 81 | $plural = $this->parser->subparse([$this, 'decideForFork']); |
74 | 82 | $next = $stream->next()->getValue(); |
|
0 commit comments