diff --git a/calc.js b/calc.js index 6c4fcba..b14f076 100644 --- a/calc.js +++ b/calc.js @@ -49,7 +49,15 @@ function buildLexer() { const Pokemon = createToken({ name: "Pokemon", pattern: new RegExp( - [...gen.species].map((s) => escapeRegExp(s.name)).join("|") + [...gen.species] + .flatMap((s) => [ + // Important: formes are expanded first because the parser takes the + // first match, and the original species is always a subset of a + // forme. + ...(s.otherFormes || []).map(escapeRegExp), + escapeRegExp(s.name), + ]) + .join("|") ), }); const Move = createToken({ @@ -336,6 +344,12 @@ function test() { res = parseAndCalculate("Tera Electric Iron Hands Wild Charge vs Basculin"); assert(res.attacker.teraType === "Electric", "should parse tera type"); + + res = parseAndCalculate("Gallade-Mega Triple Axel vs Gligar"); + assert(res.attacker.name === "Gallade-Mega", "should parse Mega forme"); + + res = parseAndCalculate("Zoroark-Hisui Night Slash vs Golem"); + assert(res.attacker.name === "Zoroark-Hisui", "should parse regional forme"); } export { parseAndCalculate, test };