def parse_and_analyse(data): p = parse(data) dispatcher = Dispatcher() res = ast_walk(p, dispatcher) return res
import sys from pprint \ import \ pprint from bento.core.parser.nodes import ast_walk from bento.core.parser.visitor import Dispatcher from bento.core.parser.parser import parse if __name__ == "__main__": if len(sys.argv) > 1: arg = sys.argv[1] data = open(arg).read() else: raise ValueError("Usage: generate foo.info") base, ext = arg.split(".") py_module = base + ".py" p = parse(data) dispatcher = Dispatcher() res = ast_walk(p, dispatcher) with open(py_module, "w") as fid: fid.write("ref = ") pprint(res, fid)
def build_ast_from_raw_dict(raw_dict, user_flags=None): dispatcher = Dispatcher(user_flags) res = ast_walk(raw_dict, dispatcher) return res
def parse(data): p = _parse(data) dispatcher = Dispatcher() return ast_walk(p, dispatcher)