from dataclasses import dataclass from parse.map_header import tokenize_line def tokenize_map_const(line): return tokenize_line(line) def tokenize_lines(lines): for line in lines: if "map_const" in line: yield tokenize_map_const(line) @dataclass class MapConstant: name: str width: int height: int def flatten(tokens): for macro, args in tokens: if macro == 'map_const': name, width, height = args yield MapConstant( name, int(width), int(height) ) def parse(prefix): path = prefix / "constants/map_constants.asm" with open(path) as f: tokens = tokenize_lines(f.read().split("\n")) return list(flatten(tokens))