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
评论列表
文章目录