from itertools import chain def is_label(token_line): return token_line[0].endswith(':') def is_data(token_line): return token_line[0] == 'db' or token_line[0] == 'dw' \ or token_line[0] == 'text_far' Label = object() Data = object() def _event(token_line): if is_label(token_line): label0, = token_line yield Label, label0.split(':')[0] elif is_data(token_line): _, args = token_line yield Data, args else: return def event(tokens): return list(chain.from_iterable(map(_event, tokens))) def pointer_table(type_args, ix): pointer_table = [] while ix < len(type_args): type, args = type_args[ix] if type is Label: break elif type is Data: evos_moves_label, = args pointer_table.append(evos_moves_label) else: assert False, type_args ix += 1 return ix, pointer_table