Commit 6cbb99b3 authored by Stefan Behnel's avatar Stefan Behnel

tiny helper class for replacing all occurrences of a node in a subtree

parent d36f3b8a
......@@ -272,6 +272,22 @@ class CythonTransform(VisitorTransform):
self.visitchildren(node)
return node
class RecursiveNodeReplacer(VisitorTransform):
"""
Recursively replace all occurrences of a node in a subtree by
another node.
"""
def __init__(self, orig_node, new_node):
super(RecursiveNodeReplacer, self).__init__()
self.orig_node, self.new_node = orig_node, new_node
def visit_Node(self, node):
self.visitchildren(node)
if node is self.orig_node:
return self.new_node
else:
return node
......
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