]> git.ipfire.org Git - thirdparty/jinja.git/commitdiff
Priority of `not` raised. It's now possible to write `not foo in bar`
authorArmin Ronacher <armin.ronacher@active-4.com>
Wed, 4 Feb 2009 17:57:27 +0000 (18:57 +0100)
committerArmin Ronacher <armin.ronacher@active-4.com>
Wed, 4 Feb 2009 17:57:27 +0000 (18:57 +0100)
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

.hgignore
CHANGES
docs/_static/style.css
docs/cache_extension.py
jinja2/parser.py
tests/test_syntax.py

index 0aa46ee2f864c218019156cf0cd7d98fb97be284..eebc869f522b7d50d3f5887eb1739b6713a7ba61 100644 (file)
--- a/.hgignore
+++ b/.hgignore
@@ -5,3 +5,4 @@
 ^(build|dist|Jinja2\.egg-info)/
 \.py[co]$
 \.DS_Store$
+^env/
diff --git a/CHANGES b/CHANGES
index ab75555cb5ddf5ecebad33f546e3e6720c0963d6..99113013c22a6d06e5603e27717d3681dea4804c 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -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
 -------------
index e6238d5e24d33507a4a03987237b8af0b02c43f3..a1c4d591247331bf6769e55b89358ac2757aae5d 100644 (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;
 }
index ec0067bb2b2958452cd097bb2b116fd1e45c3471..c736a6503fc33543f02a1770b9182e89e7158c7d 100644 (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
index c607540745a55b7439db0b3741b741c4f14821e7..b6e23df2d0d5e373487d9e5175450e7d7189ccc8 100644 (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()
index 8d14c665ce77d82d0519c5d2940a6278bb426664..2a8e46fdb4f012ccf37177aa81bad33efd5da952 100644 (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)