pokemon/tools/parse/map_constants.py
Zack Buhman a921a44b66 parse: move tokenize_line/tokenize_lines to a new module
At times I forget what I have already written. I hope that this might help keep
things more organized.
2023-07-31 16:23:55 -07:00

30 lines
720 B
Python

from dataclasses import dataclass
from functools import partial
from parse.generic import macro_line
tokenize_lines = partial(macro_line.tokenize_lines, prefix="map_const")
@dataclass
class MapConstant:
width: int
height: int
def flatten(tokens):
for macro, args in tokens:
assert macro == 'map_const', (macro, args)
name, width, height = args
yield name, MapConstant(
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"))
l = list(flatten(tokens))
d = dict(l)
assert len(l) == len(d)
return d