From d4eb18f74dc8d951a9a862c8b81d93dadafeac7e Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Tue, 11 Sep 2007 17:06:10 +0200 Subject: [PATCH] this fixes #1. --HG-- branch : trunk --- jinja/datastructure.py | 16 ++++++++++++++++ jinja/parser.py | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) 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): -- 2.26.2