Skip to content

Fix read_game() variation handling after illegal moves - #1218

Open
Shr3yash wants to merge 1 commit into
niklasf:masterfrom
Shr3yash:fix/pgn-illegal-move-variation-end
Open

Shr3yash wants to merge 1 commit into
niklasf:masterfrom
Shr3yash:fix/pgn-illegal-move-variation-end

Conversation

@Shr3yash

Copy link
Copy Markdown

Fixes #1217.

An illegal move makes read_game() skip to the end of the variation, but the closing ")" was handled the same way as a variation skipped by the visitor. read_game() now remembers why it started skipping:

  • error inside a variation: on the closing ")", call end_variation() and pop the board, so the mainline continues from the right position
  • error in the mainline: ignore an unmatched ")" and keep skipping the rest of the game, as it already does without the bracket
  • visitor returned SKIP: unchanged

Tests cover the three examples from the issue and check that deliberately skipped variations still work.

This builds on #1204 by @eeshsaxena, which found the IndexError. As you suggested there, the fix is in read_game() rather than GameBuilder.

An illegal move starts skipping to the end of the variation, but the
closing bracket was handled as if begin_variation() had returned SKIP:
the board stack was not popped after an error inside a variation, and an
unmatched ')' after an error in the mainline ended a variation that was
never started (IndexError in GameBuilder).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

read_game() loses track of variations after an illegal move

1 participant