4 * This file is part of Twig.
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
16 * {% macro input(name, value, type, size) %}
17 * <input type="{{ type|default('text') }}" name="{{ name }}" value="{{ value|e }}" size="{{ size|default(20) }}" />
23 class Twig_TokenParser_Macro extends Twig_TokenParser
25 public function parse(Twig_Token $token)
27 $lineno = $token->getLine();
28 $stream = $this->parser->getStream();
29 $name = $stream->expect(Twig_Token::NAME_TYPE)->getValue();
31 $arguments = $this->parser->getExpressionParser()->parseArguments(true, true);
33 $stream->expect(Twig_Token::BLOCK_END_TYPE);
34 $this->parser->pushLocalScope();
35 $body = $this->parser->subparse(array($this, 'decideBlockEnd'), true);
36 if ($token = $stream->nextIf(Twig_Token::NAME_TYPE)) {
37 $value = $token->getValue();
39 if ($value != $name) {
40 throw new Twig_Error_Syntax(sprintf('Expected endmacro for macro "%s" (but "%s" given).', $name, $value), $stream->getCurrent()->getLine(), $stream->getSourceContext());
43 $this->parser->popLocalScope();
44 $stream->expect(Twig_Token::BLOCK_END_TYPE);
46 $this->parser->setMacro($name, new Twig_Node_Macro($name, new Twig_Node_Body(array($body)), $arguments, $lineno, $this->getTag()));
49 public function decideBlockEnd(Twig_Token $token)
51 return $token->test('endmacro');
54 public function getTag()
60 class_alias('Twig_TokenParser_Macro', 'Twig\TokenParser\MacroTokenParser', false);