From: Armin Ronacher Date: Tue, 11 Sep 2007 15:06:10 +0000 (+0200) Subject: this fixes #1. X-Git-Tag: 2.0rc1~270 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=d4eb18f74dc8d951a9a862c8b81d93dadafeac7e;p=jinja2.git this fixes #1. --HG-- branch : trunk --- diff --git a/jinja/datastructure.py b/jinja/datastructure.py index b7cff18..8f2069d 100644 --- a/jinja/datastructure.py +++ b/jinja/datastructure.py @@ -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: diff --git a/jinja/parser.py b/jinja/parser.py index ff2684a..5702f6f 100644 --- a/jinja/parser.py +++ b/jinja/parser.py @@ -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):