Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
read_game: don't pop/end_variation while skipping
If the Visitor class enters a variation without skipping, then returns SKIP for a variation nested inside it, the traversal state is messed up when the inside variation ends. If our skip depth is anything greater than zero when we reach a ')' token, we should not visit the end of a variation or pop the board_stack, because it is being skipped completely. Short testcase: import chess, chess.pgn as pgn, io class MainlineW(pgn.GameBuilder): """Includes variations played by Black but not by White""" def begin_variation(self): if self.variation_stack[-1].turn() != chess.WHITE: return pgn.SKIP return super().begin_variation() g = pgn.read_game(io.StringIO( '1. e4 e5 (1... d5 2.exd5 Qxd5 3. Nc3 (3. c4) 3... Qa5)'), Visitor=MainlineW)
- Loading branch information