Commit 42ea77b5 authored by Stefan Behnel's avatar Stefan Behnel

support attribute value selection in TreePath

parent 5c5f0717
......@@ -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")))
......
......@@ -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:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment