summaryrefslogtreecommitdiff
path: root/inc/lib/Twig/TokenStream.php
diff options
context:
space:
mode:
Diffstat (limited to 'inc/lib/Twig/TokenStream.php')
-rw-r--r--inc/lib/Twig/TokenStream.php12
1 files changed, 8 insertions, 4 deletions
diff --git a/inc/lib/Twig/TokenStream.php b/inc/lib/Twig/TokenStream.php
index a2002b42..a78189f6 100644
--- a/inc/lib/Twig/TokenStream.php
+++ b/inc/lib/Twig/TokenStream.php
@@ -13,8 +13,7 @@
/**
* Represents a token stream.
*
- * @package twig
- * @author Fabien Potencier <fabien@symfony.com>
+ * @author Fabien Potencier <fabien@symfony.com>
*/
class Twig_TokenStream
{
@@ -45,6 +44,11 @@ class Twig_TokenStream
return implode("\n", $this->tokens);
}
+ public function injectTokens(array $tokens)
+ {
+ $this->tokens = array_merge(array_slice($this->tokens, 0, $this->current), $tokens, array_slice($this->tokens, $this->current));
+ }
+
/**
* Sets the pointer to the next token and returns the old one.
*
@@ -53,7 +57,7 @@ class Twig_TokenStream
public function next()
{
if (!isset($this->tokens[++$this->current])) {
- throw new Twig_Error_Syntax('Unexpected end of template', -1, $this->filename);
+ throw new Twig_Error_Syntax('Unexpected end of template', $this->tokens[$this->current - 1]->getLine(), $this->filename);
}
return $this->tokens[$this->current - 1];
@@ -92,7 +96,7 @@ class Twig_TokenStream
public function look($number = 1)
{
if (!isset($this->tokens[$this->current + $number])) {
- throw new Twig_Error_Syntax('Unexpected end of template', -1, $this->filename);
+ throw new Twig_Error_Syntax('Unexpected end of template', $this->tokens[$this->current + $number - 1]->getLine(), $this->filename);
}
return $this->tokens[$this->current + $number];