pokemon/tools/parse/generic/constants.py
Zack Buhman 853457a79d generate: add pokemon
This also includes a handful of functions for creating instances of a
pokemon species, though certainly not complete.
2023-08-02 23:49:42 +00:00

25 lines
600 B
Python

from functools import partial
from parse.generic import tokenize
def flatten(tokens):
for t in tokens:
if t[0] == 'const':
_, (name,) = t
yield name
elif t[0] == 'const_skip':
yield None
elif t[0] == 'const_def':
continue
elif t[0] == 'const_next':
continue
else:
assert False, t
tokenize_lines = partial(tokenize.lines, prefix='const')
def parse(prefix, path):
path = prefix / path
with open(path) as f:
return list(flatten(tokenize_lines(f.read().split('\n'))))