def __from_string_inner(cls, sexp): if not isinstance(sexp, tuple): return sexp if sexp[0] == cls.LAMBDA: return (sexp[0], sexp[1], parse_bracketed('<', '>', sexp[2], ','), cls.__from_string_inner(sexp[3])) return tuple(cls.__from_string_inner(child) for child in sexp)
def from_string(cls, string): sexp = parse_bracketed('(', ')', string) sexp = cls.__from_string_inner(sexp) return LambdaExpr(sexp)