py_ast.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:vizgen 作者: uva-graphics 项目源码 文件源码
def get_ast(source_prog):
    """Returns the ast of the program, with comments converted into string 
    literals.
    Args:
        source_prog, string, string version of the source code
    """
    wrapped_str = comment_to_str(source_prog, TRANS_PREFIXES)
    node = ast.parse(wrapped_str)
    add_parent_info(node)
    nodeList = [i for i in ast.walk(node) if (isinstance(i, ast.stmt))]
    for i in nodeList:
        if(hasattr(i,'lineno')):
            #i.orig_lineno = 1
            temp = getLineNum(i)
            if(temp != -1):
                i.orig_lineno = temp
                #a = 1
    nodeList = [i for i in ast.walk(node)]
    for i in nodeList:
        if(hasattr(i,'parent')):
            delattr(i, 'parent')
    return node
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号