Mercurial > hg > dml-open-vis
annotate src/Kachkaev/JstmplBundle/Twig/JstmplTokenParser.php @ 0:493bcb69166c
added public content
author | Daniel Wolff |
---|---|
date | Tue, 09 Feb 2016 20:54:02 +0100 |
parents | |
children |
rev | line source |
---|---|
Daniel@0 | 1 <?php |
Daniel@0 | 2 |
Daniel@0 | 3 namespace Kachkaev\JstmplBundle\Twig; |
Daniel@0 | 4 |
Daniel@0 | 5 class JstmplTokenParser extends \Twig_TokenParser |
Daniel@0 | 6 { |
Daniel@0 | 7 public function parse(\Twig_Token $token) |
Daniel@0 | 8 { |
Daniel@0 | 9 $lineno = $token->getLine(); |
Daniel@0 | 10 |
Daniel@0 | 11 $stream = $this->parser->getStream(); |
Daniel@0 | 12 |
Daniel@0 | 13 while (!$stream->test(\Twig_Token::BLOCK_END_TYPE)) { |
Daniel@0 | 14 if ($stream->test(\Twig_Token::NAME_TYPE, 'id')) { |
Daniel@0 | 15 // id='tmpl_id' |
Daniel@0 | 16 $stream->next(); |
Daniel@0 | 17 $stream->expect(\Twig_Token::OPERATOR_TYPE, '='); |
Daniel@0 | 18 $id = $stream->expect(\Twig_Token::STRING_TYPE)->getValue(); |
Daniel@0 | 19 } else { |
Daniel@0 | 20 $token = $stream->getCurrent(); |
Daniel@0 | 21 throw new \Twig_Error_Syntax(sprintf('Unexpected token "%s" of value "%s"', \Twig_Token::typeToEnglish($token->getType(), $token->getLine()), $token->getValue()), $token->getLine()); |
Daniel@0 | 22 } |
Daniel@0 | 23 } |
Daniel@0 | 24 |
Daniel@0 | 25 $stream->expect(\Twig_Token::BLOCK_END_TYPE); |
Daniel@0 | 26 |
Daniel@0 | 27 $endtag = 'end'.$this->getTag(); |
Daniel@0 | 28 $test = function(\Twig_Token $token) use($endtag) { |
Daniel@0 | 29 return $token->test($endtag); |
Daniel@0 | 30 }; |
Daniel@0 | 31 $body = $this->parser->subparse($test, true); |
Daniel@0 | 32 |
Daniel@0 | 33 $stream->expect(\Twig_Token::BLOCK_END_TYPE); |
Daniel@0 | 34 |
Daniel@0 | 35 return new JstmplNode($id, $body, $lineno, $this->getTag()); |
Daniel@0 | 36 } |
Daniel@0 | 37 |
Daniel@0 | 38 public function getTag() |
Daniel@0 | 39 { |
Daniel@0 | 40 return 'jstmpl'; |
Daniel@0 | 41 } |
Daniel@0 | 42 } |