123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
-
-
-
-
- class Twig_TokenParser_Block extends Twig_TokenParser
- {
-
-
- public function parse(Twig_Token $token)
- {
- $lineno = $token->getLine();
- $stream = $this->parser->getStream();
- $name = $stream->expect(Twig_Token::NAME_TYPE)->getValue();
- if ($this->parser->hasBlock($name)) {
- throw new Twig_Error_Syntax("The block '$name' has already been defined", $lineno);
- }
- $this->parser->pushLocalScope();
- $this->parser->pushBlockStack($name);
-
- if ($stream->test(Twig_Token::BLOCK_END_TYPE)) {
- $stream->next();
-
- $body = $this->parser->subparse(array($this, 'decideBlockEnd'), true);
- if ($stream->test(Twig_Token::NAME_TYPE)) {
- $value = $stream->next()->getValue();
-
- if ($value != $name) {
- throw new Twig_Error_Syntax(sprintf("Expected endblock for block '$name' (but %s given)", $value), $lineno);
- }
- }
- } else {
- $body = new Twig_Node(array(
- new Twig_Node_Print($this->parser->getExpressionParser()->parseExpression(), $lineno),
- ));
- }
- $stream->expect(Twig_Token::BLOCK_END_TYPE);
-
- $block = new Twig_Node_Block($name, $body, $lineno);
- $this->parser->setBlock($name, $block);
- $this->parser->popBlockStack();
- $this->parser->popLocalScope();
-
- return new Twig_Node_BlockReference($name, $lineno, $this->getTag());
- }
-
- public function decideBlockEnd(Twig_Token $token)
- {
- return $token->test('endblock');
- }
-
-
-
- public function getTag()
- {
- return 'block';
- }
- }
|