From: Fabien Potencier Date: Wed, 22 Dec 2010 10:49:01 +0000 (+0100) Subject: readded TokenStream::look() X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=d72b6ad1360e002e927ddf7d3b75867cbadf12a3;p=web%2Fkonrad%2Ftwig.git readded TokenStream::look() --- diff --git a/doc/advanced.rst b/doc/advanced.rst index 9df1dd5..ce551af 100644 --- a/doc/advanced.rst +++ b/doc/advanced.rst @@ -359,6 +359,8 @@ from the token stream (``$this->parser->getStream()``): type/value a syntax error is thrown. Otherwise, if the type and value are correct, the token is returned and the stream moves to the next token. +* ``look()``: Looks a the next token without consuming it. + Parsing expressions is done by calling the ``parseExpression()`` like we did for the ``set`` tag. diff --git a/lib/Twig/TokenStream.php b/lib/Twig/TokenStream.php index d8e8edf..0a7ef90 100644 --- a/lib/Twig/TokenStream.php +++ b/lib/Twig/TokenStream.php @@ -67,6 +67,20 @@ class Twig_TokenStream } /** + * Looks at the next token. + * + * @return Twig_Token + */ + public function look() + { + if (!isset($this->tokens[$this->current + 1])) { + throw new Twig_Error_Syntax('Unexpected end of template'); + } + + return $this->tokens[$this->current + 1]; + } + + /** * test() current token * * @return bool