Extract the SAN token list from PGN movetext (strip headers/comments/numbers/result).
(pgn: str)
| 187 | |
| 188 | |
| 189 | def _movetext(pgn: str) -> list[str]: |
| 190 | """Extract the SAN token list from PGN movetext (strip headers/comments/numbers/result).""" |
| 191 | lines = [ln for ln in pgn.splitlines() if not ln.startswith("[")] |
| 192 | text = " ".join(lines) |
| 193 | text = re.sub(r"\{[^}]*\}", " ", text) # comments |
| 194 | text = re.sub(r"\([^)]*\)", " ", text) # variations |
| 195 | text = re.sub(r"\$\d+", " ", text) # NAGs |
| 196 | text = re.sub(r"\d+\.(\.\.)?", " ", text) # move numbers |
| 197 | out = [] |
| 198 | for tok in text.split(): |
| 199 | if tok in ("1-0", "0-1", "1/2-1/2", "*"): |
| 200 | break |
| 201 | out.append(tok) |
| 202 | return out |
| 203 | |
| 204 | |
| 205 | def _header(pgn: str, key: str) -> str | None: |