| @@ 22-64 (lines=43) @@ | ||
| 19 | /** |
|
| 20 | * Parser for container/endcontainer blocks. |
|
| 21 | */ |
|
| 22 | class ContainerTokenParser extends \Twig_TokenParser |
|
| 23 | { |
|
| 24 | /** |
|
| 25 | * @param \Twig_Token $token |
|
| 26 | * |
|
| 27 | * @return bool |
|
| 28 | */ |
|
| 29 | public function decideEnd(\Twig_Token $token) |
|
| 30 | { |
|
| 31 | return $token->test('endcontainer'); |
|
| 32 | } |
|
| 33 | ||
| 34 | /** |
|
| 35 | * {@inheritdoc} |
|
| 36 | */ |
|
| 37 | public function getTag() |
|
| 38 | { |
|
| 39 | return 'container'; |
|
| 40 | } |
|
| 41 | ||
| 42 | /** |
|
| 43 | * {@inheritdoc} |
|
| 44 | */ |
|
| 45 | public function parse(\Twig_Token $token) |
|
| 46 | { |
|
| 47 | $lineno = $token->getLine(); |
|
| 48 | $stream = $this->parser->getStream(); |
|
| 49 | ||
| 50 | $name = $this->parser->getExpressionParser()->parseExpression(); |
|
| 51 | ||
| 52 | $parameters = null; |
|
| 53 | if ($stream->nextIf(\Twig_Token::NAME_TYPE, 'with')) { |
|
| 54 | $parameters = $this->parser->getExpressionParser()->parseExpression(); |
|
| 55 | } |
|
| 56 | ||
| 57 | $stream->expect(\Twig_Token::BLOCK_END_TYPE); |
|
| 58 | $body = $this->parser->subparse([$this, 'decideEnd'], true); |
|
| 59 | ||
| 60 | $stream->expect(\Twig_Token::BLOCK_END_TYPE); |
|
| 61 | ||
| 62 | return new ContainerNode($name, $parameters, $body, $lineno, $this->getTag()); |
|
| 63 | } |
|
| 64 | } |
|
| 65 | ||
| @@ 22-62 (lines=41) @@ | ||
| 19 | /** |
|
| 20 | * Parser for gimme/endgimme blocks. |
|
| 21 | */ |
|
| 22 | class GimmeTokenParser extends \Twig_TokenParser |
|
| 23 | { |
|
| 24 | /** |
|
| 25 | * @param \Twig_Token $token |
|
| 26 | * |
|
| 27 | * @return bool |
|
| 28 | */ |
|
| 29 | public function decideCacheEnd(\Twig_Token $token) |
|
| 30 | { |
|
| 31 | return $token->test('endgimme'); |
|
| 32 | } |
|
| 33 | ||
| 34 | /** |
|
| 35 | * {@inheritdoc} |
|
| 36 | */ |
|
| 37 | public function getTag() |
|
| 38 | { |
|
| 39 | return 'gimme'; |
|
| 40 | } |
|
| 41 | ||
| 42 | /** |
|
| 43 | * {@inheritdoc} |
|
| 44 | */ |
|
| 45 | public function parse(\Twig_Token $token) |
|
| 46 | { |
|
| 47 | $lineno = $token->getLine(); |
|
| 48 | $stream = $this->parser->getStream(); |
|
| 49 | ||
| 50 | $annotation = $this->parser->getExpressionParser()->parseAssignmentExpression(); |
|
| 51 | $parameters = null; |
|
| 52 | if ($stream->nextIf(\Twig_Token::NAME_TYPE, 'with')) { |
|
| 53 | $parameters = $this->parser->getExpressionParser()->parseExpression(); |
|
| 54 | } |
|
| 55 | ||
| 56 | $stream->expect(\Twig_Token::BLOCK_END_TYPE); |
|
| 57 | $body = $this->parser->subparse([$this, 'decideCacheEnd'], true); |
|
| 58 | $stream->expect(\Twig_Token::BLOCK_END_TYPE); |
|
| 59 | ||
| 60 | return new GimmeNode($annotation, $parameters, $body, $lineno, $this->getTag()); |
|
| 61 | } |
|
| 62 | } |
|
| 63 | ||