added parsing code for "for item in seq recursive" and improved parser interface a bit
--HG--
branch : trunk
diff --git a/jinja2/lexer.py b/jinja2/lexer.py
index d950025..639b285 100644
--- a/jinja2/lexer.py
+++ b/jinja2/lexer.py
@@ -219,19 +219,27 @@
for x in xrange(n):
self.next()
- def next(self, skip_eol=True):
+ def next_if(self, expr):
+ """Perform the token test and return the token if it matched.
+ Otherwise the return value is `None`.
+ """
+ if self.current.test(expr):
+ return self.next()
+
+ def skip_if(self, expr):
+ """Like `next_if` but only returns `True` or `False`."""
+ return self.next_if(expr) is not None
+
+ def next(self):
"""Go one token ahead and return the old one"""
rv = self.current
- while 1:
- if self._pushed:
- self.current = self._pushed.popleft()
- elif self.current.type is not 'eof':
- try:
- self.current = self._next()
- except StopIteration:
- self.close()
- if not skip_eol or self.current.type is not 'eol':
- break
+ if self._pushed:
+ self.current = self._pushed.popleft()
+ elif self.current.type is not 'eof':
+ try:
+ self.current = self._next()
+ except StopIteration:
+ self.close()
return rv
def close(self):