1 | <?php |
||
31 | final class TokenParser extends \Twig_TokenParser |
||
32 | { |
||
33 | /** |
||
34 | * {@inheritdoc} |
||
35 | */ |
||
36 | 7 | public function parse(\Twig_Token $token) |
|
37 | { |
||
38 | 7 | $lineno = $token->getLine(); |
|
39 | 7 | $stream = $this->parser->getStream(); |
|
40 | |||
41 | 7 | if ($stream->test(\Twig_Token::BLOCK_END_TYPE)) { |
|
42 | 2 | $priority = null; |
|
43 | 6 | } elseif ($stream->test(\Twig_Token::OPERATOR_TYPE)) { |
|
44 | 2 | $operator = $stream->next()->getValue(); |
|
45 | |||
46 | 2 | if (!in_array($operator, array('-', '+'), true)) { |
|
47 | 1 | throw new \Twig_Error_Syntax(sprintf('Priority can be given as positive and/or negative number, operator "%s" is not allowed.', $operator)); |
|
48 | } |
||
49 | |||
50 | 1 | $priority = $stream->expect(\Twig_Token::NUMBER_TYPE)->getValue(); |
|
51 | |||
52 | 1 | if ($operator == '-') { |
|
53 | 1 | $priority = -$priority; |
|
54 | } |
||
55 | |||
56 | } else { |
||
57 | 4 | $priority = $stream->expect(\Twig_Token::NUMBER_TYPE)->getValue(); |
|
58 | } |
||
59 | |||
60 | 6 | $stream->expect(\Twig_Token::BLOCK_END_TYPE); |
|
61 | 6 | $body = $this->parser->subparse(array($this, 'decideBufferizeEnd'), true); |
|
62 | 6 | $stream->expect(\Twig_Token::BLOCK_END_TYPE); |
|
63 | |||
64 | 6 | return new Node(array('body' => $body), array('execution_priority' => $priority), $lineno, $this->getTag()); |
|
65 | } |
||
66 | |||
67 | 6 | public function decideBufferizeEnd(\Twig_Token $token) |
|
71 | |||
72 | /** |
||
73 | * {@inheritdoc} |
||
74 | */ |
||
75 | 9 | public function getTag() |
|
79 | } |
||
80 |