support attribute value selection in TreePath
authorStefan Behnel <scoder@users.berlios.de>
Fri, 18 Sep 2009 06:25:16 +0000 (08:25 +0200)
committerStefan Behnel <scoder@users.berlios.de>
Fri, 18 Sep 2009 06:25:16 +0000 (08:25 +0200)
Cython/Compiler/Tests/TestTreePath.py
Cython/Compiler/TreePath.py

index 648154092ff115cdb1356ad94c14e9062e8dd92e..296aff6a7a7965a9ad3b3995d494f9d69bed208d 100644 (file)
@@ -24,6 +24,11 @@ class TestTreePath(TransformTest):
         self.assertEquals(1, len(find_all(t, "//ReturnStatNode")))
         self.assertEquals(1, len(find_all(t, "//DefNode//ReturnStatNode")))
 
+    def test_node_path_attribute(self):
+        t = self._build_tree()
+        self.assertEquals(2, len(find_all(t, "//NameNode/@name")))
+        self.assertEquals(['fun', 'decorator'], find_all(t, "//NameNode/@name"))
+
     def test_node_path_child(self):
         t = self._build_tree()
         self.assertEquals(1, len(find_all(t, "//DefNode/ReturnStatNode/NameNode")))
index 74aaeba7888e679d86a78a3998f20b899548e917..81c0a5741dce6ad7a69a4fdc81ed0a33f5a561f2 100644 (file)
@@ -136,10 +136,14 @@ def handle_attribute(next, token):
     if token[0]:
         raise ValueError("Expected attribute name")
     name = token[1]
-    token = next()
     value = None
-    if token[0] == '=':
-        value = parse_path_value(next)
+    try:
+        token = next()
+    except StopIteration:
+        pass
+    else:
+        if token[0] == '=':
+            value = parse_path_value(next)
     if value is None:
         def select(result):
             for node in result: