Skip to content

Conversation

@mikeb26
Copy link
Contributor

@mikeb26 mikeb26 commented Jul 12, 2025

These commits in aggregate add a feature to the Scanner to expand variations into individual Game instances during parsing. Together they address #52. Please note that tests will not pass until #55 (comment) is merged as the new tests added here depend on that bugfix. I intentionally didn't re-include it with this PR to avoid confusion.

mikeb26 added 5 commits July 12, 2025 00:50
This commit is part of a series which adds a feature to the Scanner to
expand variations into individual Game instances during parsing. This
commit specifically adds Move.Clone(), a utility function to deep copy
a Move instance.
This commit is part of a series which adds a feature to the Scanner to
expand variations into individual Game instances during parsing. This
commit specifically adds Game.Split(), the core functionality
introduced by this series. Given a Game with a main line and
possibly many variations, Game.Split() will return a slice of Games, 1
per variation, which each individually have only a single main line.
This makes it convenient for callers who can then utilize Game.Moves()
and other methods which only work on the main line.
This commit is part of a series which adds a feature to the Scanner to
expand variations into individual Game instances during parsing. This
commit specifically adds Scanner.ParseNext(). Scanner.ParseNext() is a
higher level convenience iterator combining the functionality of
ScanGame(), TokenizeGame(), NewParser(), and Parse(). This will later
be extended to support expanded variations in part 4.
This commit is part of a series which adds a feature to the Scanner to
expand variations into individual Game instances during parsing. This
commit specifically adds ScannerOption, and the first ScannerOption
WithExpandVariations(). Additionally this commit implements the option
by taking advantage of part 2's Game.Split() function within
Scanner.ParseNext() and caches the result in Scanner.nextParsedGames
to be utilized in subsequent invocations.
This commit is part of a series which adds a feature to the Scanner to
expand variations into individual Game instances during parsing. This
commit specifically updates the documentation on scanning PGNs.
@CorentinGS CorentinGS requested a review from Copilot July 12, 2025 09:52
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Adds a new Scanner option to emit each variation as its own Game and simplifies parsing loops.

  • Introduce WithExpandVariations and internal buffering (nextParsedGames) plus a new ParseNext method.
  • Implement Game.Split to derive separate games from variations and add Move.Clone with deep‐copy tests.
  • Update tests (*_test.go) to use ParseNext and cover expansion, splitting, and cloning behavior.

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
scanner.go Added ScannerOpts, WithExpandVariations, updated HasNext, implemented ParseNext.
scanner_test.go New tests for expanded and non-expanded variation parsing.
pgn_test.go Refactored tests to call ParseNext instead of manual scan/tokenize/parse.
game.go Added Game.Split, collectPaths, buildOneGameFromPath.
game_test.go Tests for Game.Split with and without variations.
move.go Added Move.Clone method.
move_test.go assertMovesAreEqual helper and TestMoveClone for deep copy.
README.md Updated examples to demonstrate ParseNext and WithExpandVariations.
Comments suppressed due to low confidence (3)

README.md:396

  • The example shows log.Fatal with formatting verbs. To match intended behavior, use log.Fatalf so the error is formatted correctly.
		log.Fatal("Failed to parse game: %v", err)

move_test.go:469

  • The error message references 's2' but is checking the 'promo' field; update the message to reflect 'promo'.
		t.Fatalf("cloned mv %s s2 is not the same", m1)

move_test.go:483

  • This message is in the branch checking children length but mentions 'len(command)'; it should say 'len(children)'.
		t.Fatalf("cloned mv %s len(command) is not the same", m1)

Co-authored-by: Copilot <[email protected]>
@CorentinGS CorentinGS merged commit 32ce606 into CorentinGS:main Jul 12, 2025
6 checks passed
@mikeb26 mikeb26 deleted the expandVar branch July 12, 2025 14:13
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.

2 participants