somewhat hackish fix for supporting not() in TreePath - needs to be reconsidered ...
authorStefan Behnel <scoder@users.berlios.de>
Fri, 18 Sep 2009 13:01:14 +0000 (15:01 +0200)
committerStefan Behnel <scoder@users.berlios.de>
Fri, 18 Sep 2009 13:01:14 +0000 (15:01 +0200)
Cython/Compiler/Tests/TestTreePath.py
Cython/Compiler/TreePath.py

index 296aff6a7a7965a9ad3b3995d494f9d69bed208d..8c6e7fe5072d9c19ab0728a3d5430150e5adab0b 100644 (file)
@@ -38,6 +38,11 @@ class TestTreePath(TransformTest):
         t = self._build_tree()
         self.assertEquals(2, len(find_all(t, "//NameNode[@name]")))
 
+    def test_node_path_attribute_exists_not(self):
+        t = self._build_tree()
+        self.assertEquals(0, len(find_all(t, "//NameNode[not(@name)]")))
+        self.assertEquals(2, len(find_all(t, "//NameNode[not(@honking)]")))
+
     def test_node_path_attribute_string_predicate(self):
         t = self._build_tree()
         self.assertEquals(1, len(find_all(t, "//NameNode[@name = 'decorator']")))
index 81c0a5741dce6ad7a69a4fdc81ed0a33f5a561f2..30612a50605b39d8bcaf07718502c62847392a7d 100644 (file)
@@ -49,7 +49,7 @@ def parse_func(next, token):
     token = next()
     if token[0] != '(':
         raise ValueError("Expected '(' after function name '%s'" % name)
-    predicate = handle_predicate(next, token, end_marker=')')
+    predicate = handle_predicate(next, token)
     return name, predicate
 
 def handle_func_not(next, token):
@@ -60,7 +60,7 @@ def handle_func_not(next, token):
 
     def select(result):
         for node in result:
-            if _get_first_or_none(predicate(node)) is not None:
+            if _get_first_or_none(predicate([node])) is None:
                 yield node
     return select
 
@@ -176,10 +176,10 @@ def parse_path_value(next):
             raise ValueError("Invalid attribute predicate: '%s'" % value)
     return value
 
-def handle_predicate(next, token, end_marker=']'):
+def handle_predicate(next, token):
     token = next()
     selector = []
-    while token[0] != end_marker:
+    while token[0] != ']':
         selector.append( operations[token[0]](next, token) )
         try:
             token = next()