def parse(f): dic = {} content = read(f) transitions = content.split("\n\n") print(transitions[0]) transitions = transitions[1:] for t in transitions: try: src, dst = t.split("\n") except: if len(t.split("\n")) == 1: break src, dst, _ = t.split("\n") state, symbol = src.split(",") state_key = State.by_rep(state) symbol_key = Symbol.by_rep(symbol) if state_key not in dic: dic[state_key] = {} dic[state_key].update({symbol_key: make_tuple(dst)}) return dic
def make_tuple(dst): state, symbol, direc = dst.split(",") return (State.by_rep(state), Symbol.by_rep(symbol), Direction.by_rep(direc))