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_ast_to_tuple() - Given a class, create a closue that
converts from the given AST class to nested tuple/list
representation of the abstract tree constructors.
Note that this won't work for the wrapped AST objects.

        def mk_ast_to_tuple (ast_class):
    """mk_ast_to_tuple() - Given a class, create a closue that
    converts from the given AST class to nested tuple/list
    representation of the abstract tree constructors.
    Note that this won't work for the wrapped AST objects."""
    def ast_to_tuple (ast_elem):
        ret_val = ast_elem
        elem_type = type(ast_elem)
        if issubclass(elem_type, ast_class):
            node_constructor_co = elem_type.__init__.im_func.func_code
            constructor_args = node_constructor_co.co_varnames[1:]
            constructor_vals = [ast_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 = [ast_to_tuple(child_elem) for child_elem in ast_elem]
            if elem_type == tuple:
                ret_val = tuple(ret_val)
        return ret_val
    return ast_to_tuple
        


src/m/y/mython-HEAD/basil/lang/mython/myfront_transformer.py   mython(Download)
    import pprint
    # ____________________________________________________________
    ast_to_tuple = ASTUtils.mk_ast_to_tuple(myfront_ast.AST)
    pyast_to_tuple = ASTUtils.mk_pyast_to_tuple(myfront_ast.__dict__)
    # ____________________________________________________________
    import os, tokenize, MyRealParser, pprint, ASTUtils, _ast
    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: