Priority of not raised. It's now possible to write not foo in bar

as an alias to `foo not in bar` like in python.  Previously the grammar
required parentheses (`not (foo in bar)`) which was odd.

--HG--
branch : trunk
This commit is contained in:
Armin Ronacher 2009-02-04 18:57:27 +01:00
parent 8de6f18b9d
commit d89f0f3def
6 changed files with 21 additions and 8 deletions

View File

@ -5,3 +5,4 @@
^(build|dist|Jinja2\.egg-info)/
\.py[co]$
\.DS_Store$
^env/

View File

@ -7,6 +7,9 @@ Version 2.2
- Include statements can now be marked with ``ignore missing`` to skip
non existing templates.
- Priority of `not` raised. It's now possible to write `not foo in bar`
as an alias to `foo not in bar` like in python. Previously the grammar
required parentheses (`not (foo in bar)`) which was odd.
Version 2.1.1
-------------

View File

@ -253,6 +253,7 @@ h3:hover > a.headerlink,
h4:hover > a.headerlink,
h5:hover > a.headerlink,
h6:hover > a.headerlink,
dt:hover > a.headerlink,
dt:hover > a.headerlink {
visibility: visible;
}

View File

@ -51,6 +51,6 @@ class FragmentCacheExtension(Extension):
rv = self.environment.fragment_cache.get(key)
if rv is None:
return rv
rv = caller()
self.environment.fragment_cache.add(key, rv, timeout)
rv = caller()
self.environment.fragment_cache.add(key, rv, timeout)
return rv

View File

@ -333,13 +333,19 @@ class Parser(object):
def parse_and(self):
lineno = self.stream.current.lineno
left = self.parse_compare()
left = self.parse_not()
while self.stream.skip_if('name:and'):
right = self.parse_compare()
right = self.parse_not()
left = nodes.And(left, right, lineno=lineno)
lineno = self.stream.current.lineno
return left
def parse_not(self):
if self.stream.current.test('name:not'):
lineno = self.stream.next().lineno
return nodes.Not(self.parse_not(), lineno=lineno)
return self.parse_compare()
def parse_compare(self):
lineno = self.stream.current.lineno
expr = self.parse_add()
@ -445,10 +451,6 @@ class Parser(object):
def parse_unary(self):
token_type = self.stream.current.type
lineno = self.stream.current.lineno
if token_type == 'name' and self.stream.current.value == 'not':
self.stream.next()
node = self.parse_unary()
return nodes.Not(node, lineno=lineno)
if token_type == 'sub':
self.stream.next()
node = self.parse_unary()

View File

@ -189,3 +189,9 @@ def test_test_chaining(env):
def test_string_concatenation(env):
tmpl = env.from_string('{{ "foo" "bar" "baz" }}')
assert tmpl.render() == 'foobarbaz'
def test_notin(env):
bar = xrange(100)
tmpl = env.from_string('''{{ not 42 in bar }}''')
assert tmpl.render(bar=bar) == unicode(not 42 in bar)