From d72b6ad1360e002e927ddf7d3b75867cbadf12a3 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 22 Dec 2010 11:49:01 +0100 Subject: [PATCH] readded TokenStream::look() --- doc/advanced.rst | 2 ++ lib/Twig/TokenStream.php | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 0 deletions(-) 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 -- 1.7.2.5