Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(2)  |  Call(2)  |  Derive(0)  |  Import(0)
mk_pyast_to_tuple() - Given a namespace for determining the
constructor order, return a function that converts from Python
AST's to a nested tuple/list representation.

        def mk_pyast_to_tuple (ast_dict):
    """mk_pyast_to_tuple() - Given a namespace for determining the
    constructor order, return a function that converts from Python
    AST's to a nested tuple/list representation."""
    import _ast
    def pyast_to_tuple (ast_elem):
        ret_val = ast_elem
        elem_type = type(ast_elem)
        if issubclass(elem_type, _ast.AST):
            elem_type_name = elem_type.__name__
            elem_type_analog = ast_dict[elem_type_name]
            analog_constructor_co = elem_type_analog.__init__.im_func.func_code
            constructor_args = analog_constructor_co.co_varnames[1:]
            constructor_vals = [pyast_to_tuple(getattr(ast_elem, arg))
                                for arg in constructor_args]
            ret_val = (elem_type_name, constructor_vals)
        elif elem_type in (list, tuple):
            ret_val = [pyast_to_tuple(child_elem) for child_elem in ast_elem]
            if elem_type == tuple:
                ret_val = tuple(ret_val)
        return ret_val
    return pyast_to_tuple
        


src/m/y/mython-HEAD/basil/lang/mython/myfront_transformer.py   mython(Download)
    # ____________________________________________________________
    ast_to_tuple = ASTUtils.mk_ast_to_tuple(myfront_ast.AST)
    pyast_to_tuple = ASTUtils.mk_pyast_to_tuple(myfront_ast.__dict__)
    # ____________________________________________________________
    def myparse (text):
    if len(args) > 0:
        ast_to_tuple = ASTUtils.mk_ast_to_tuple(AST)
        pyast_to_tuple = ASTUtils.mk_pyast_to_tuple(globals())
        for file_name in args:
            tokenizer = tokenize.generate_tokens(open(file_name).readline)