def build_pattern(builder, node): old = builder.__class__ builder.__class__ = SyntaxBuilder try: return build(builder, node) finally: builder.__class__ = old
def IfElse(self, tval, cond, fval): return IfElse(build(self, tval), build(self, cond), build(self, fval))
def method(self, items): result = build(self, items[0]) for item in items[1:]: result = nt(result, build(self, item)) return result
def method(self, left, right): return nt(build(self, left), build(self, right))
def method(self, expr): return nt(build(self, expr))
def Compare(self, expr, ops): return Compare(build(self, expr), [(op == '<>' and '!=' or op, build(self, arg)) for op, arg in ops])
def Getattr(self, expr, attr): return Getattr(build(self, expr), attr)
def Slice3(self, start, stop, stride): start = start and build(self, start) or Pass stop = stop and build(self, stop) or Pass stride = stride and build(self, stride) or Pass return BuildSlice(start, stop, stride)
def Slice2(self, start, stop): start = start and build(self, start) or Pass stop = stop and build(self, stop) or Pass return GetSlice(Pass, start, stop)
def Subscript(self, left, right): expr = build(self, left) key = build(self, right) if isinstance(key, GetSlice): return GetSlice(expr, key.start, key.stop) return Getitem(expr, key)