move: add constants and moves parsers

This commit is contained in:
Zack Buhman 2023-07-31 17:21:11 -07:00
parent a921a44b66
commit f4aad91349
2 changed files with 50 additions and 0 deletions

View File

@ -0,0 +1,17 @@
from functools import partial
from parse.generic import macro_line
tokenize_lines = partial(macro_line.tokenize_lines, prefix='const ')
def flatten(tokens):
index = 0
for t in tokens:
assert t[0] == 'const', t
_, (name,) = t
yield name, index
index += 1
def parse(prefix):
path = prefix / 'constants/move_constants.asm'
with open(path) as f:
return dict(flatten(tokenize_lines(f.read().split('\n'))))

33
tools/parse/move/moves.py Normal file
View File

@ -0,0 +1,33 @@
from dataclasses import dataclass
from functools import partial
from parse import number
from parse.generic import macro_line
tokenize_lines = partial(macro_line.tokenize_lines, prefix='move ')
@dataclass
class Move:
name: str
effect: str
power: int
type: str
accuracy: int
pp: int
def flatten(tokens):
for t in tokens:
assert t[0] == 'move', t
_, (name, effect, power, type, accuracy, pp) = t
return Move(
name,
effect,
number(power),
type,
number(accuracy),
number(pp)
)
def parse(prefix):
path = prefix / 'data/moves/moves.asm'
with open(path) as f:
return dict(flatten(tokenize_lines(f.read().split('\n'))))