def concat_ids(ast): "replaces AmbNames by Ids" for exp in itertools.chain(aterm.reverse(ast.findall("AmbName")),aterm.reverse(ast.findall("PackageOrTypeName"))): if len(exp)==1: exp.replace(exp[0]) elif len(exp)==2: if exp[0].name == "Id" and exp[1].name == "Id": exp.replace(aterm.decode('Id("%s.%s")' % (exp[0][0],exp[1][0]) )) return ast
def fix_str_add(ast): "replace str + expr with str + str(expr)" for p in aterm.reverse(ast.findall("Plus")): if len(p)==2: if is_string(p[0]) or is_string(p[1]): if not is_string(p[0]): p[0].replace(make_string(p[0])) if not is_string(p[1]): p[1].replace(make_string(p[1]))