def__call__(self, *args, **kw): typ = args[self.param_index].__class__ # BUG FIX: use __class__ here d = self.targets.get(typ) if d isnotNone: return d(*args, **kw) else: issub = issubclass t = self.targets ks = t.iterkeys() return [t[k](*args, **kw) for k in ks if issub(typ, k)]
classAbstractSyntaxTreeVisitor(object): @v.on('node') defvisit(self, node): """ This is the generic method that initializes the dynamic dispatcher. """
@v.when(BaseNode) defvisit(self, node): """ Will run for nodes that do specifically match the provided type. """ print"Unrecognized node:", node
@v.when(AssignmentExpression) defvisit(self, node): """ Matches nodes of type AssignmentExpression. """ node.children[0].accept(self) sys.stdout.write('=') node.children[1].accept(self)