this fixes #1.
authorArmin Ronacher <armin.ronacher@active-4.com>
Tue, 11 Sep 2007 15:06:10 +0000 (17:06 +0200)
committerArmin Ronacher <armin.ronacher@active-4.com>
Tue, 11 Sep 2007 15:06:10 +0000 (17:06 +0200)
--HG--
branch : trunk

jinja/datastructure.py
jinja/parser.py

index b7cff18184c262552971c07c42a80a4baa46066e..8f2069d7f056c282fce6ff2352cd4e8dc052426f 100644 (file)
@@ -529,6 +529,11 @@ class TokenStream(object):
     """
     A token stream wraps a generator and supports pushing tokens back.
     It also provides some functions to expect tokens and similar stuff.
+
+    Important note: Do never push more than one token back to the
+                    stream. Although the stream object won't stop you
+                    from doing so, the behavior is undefined. Multiple
+                    pushed tokens are only used internally!
     """
 
     def __init__(self, generator, filename):
@@ -577,6 +582,17 @@ class TokenStream(object):
         for x in xrange(n):
             self.next()
 
+    def shift(self, token):
+        """
+        Push one token into the stream.
+        """
+        old_current = self.current
+        self.next()
+        self.push(self.current)
+        self.push(old_current)
+        self.push(token)
+        self.next()
+
     def next(self):
         """Go one token ahead."""
         if self._pushed:
index ff2684ac4430f80c49298a5baca4353aa1f8a2e6..5702f6feadf4e174c4b95b7120b9926074dc9fbe 100644 (file)
@@ -1137,7 +1137,7 @@ class Parser(object):
             else:
                 extends = None
                 if leading_whitespace:
-                    self.stream.push(leading_whitespace)
+                    self.stream.shift(leading_whitespace)
 
             body = self.subparse(None)
             def walk(nodelist, stack):