30 lines
707 B
Python
30 lines
707 B
Python
from dataclasses import dataclass
|
|
from functools import partial
|
|
|
|
from parse.generic import tokenize
|
|
|
|
tokenize_lines = partial(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
|