<?php
namespace Moto\Twig\Widgets; use Moto; use Twig_TokenParser; use Twig_Token; use Twig_Error_Syntax; class TokenParser extends Twig_TokenParser { public function decideBlockEnd(Twig_Token $token) { return $token->test('endWidget'); } public function getTag() { return 'widget'; } public function parse(Twig_Token $token) { $lineno = $token->getLine(); $widget = $this->parser->getExpressionParser()->parseExpression(); $stream = $this->parser->getStream(); $stream->expect(Twig_Token::BLOCK_END_TYPE); $body = $this->parser->subparse([$this, 'decideBlockEnd']); $next = $stream->next(); if (!$next) { throw new Twig_Error_Syntax('Not next token', $stream->getCurrent()->getLine(), $stream->getSourceContext()); } if ($next->getValue() !== 'endWidget') { throw new Twig_Error_Syntax(sprintf('Expected endblock for block "%s" (but "%s" given).', 'endWidget', $next->getValue()), $stream->getCurrent()->getLine(), $stream->getSourceContext()); } $stream->expect(Twig_Token::BLOCK_END_TYPE); return new Moto\Twig\Widgets\WidgetNode($widget, $body, $lineno, $this->getTag()); } } 