feat: preserve PGN annotation structure - #117
Merged
Merged
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #117 +/- ##
==========================================
+ Coverage 70.32% 75.40% +5.07%
==========================================
Files 27 27
Lines 4186 4289 +103
==========================================
+ Hits 2944 3234 +290
+ Misses 1110 914 -196
- Partials 132 141 +9 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
CorentinGS
force-pushed
the
fix/annotation-structure
branch
3 times, most recently
from
June 3, 2026 08:03
fdd76b9 to
60f222b
Compare
CorentinGS
force-pushed
the
fix/annotation-structure
branch
from
June 19, 2026 07:34
60f222b to
9aab252
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR preserves PGN comment annotation structure instead of flattening every annotation into a single text/comment map representation.
It keeps each PGN
{...}comment block as an ordered list of text and command annotation items, so round-tripping a game can preserve:[%clk ...]New API
New exported types in
move.go:New exported method:
Move.CommentBlocks()returns a defensive copy of the structured PGN comment blocks for a move. Use it when an importer/exporter needs access to the original block boundaries or ordered comment/command items.Example:
Legacy API Compatibility
The existing annotation helpers remain available:
Move.Comments()Move.GetCommand()Move.SetCommand()Move.SetComment()Move.AddComment()Compatibility behavior:
Move.Comments()still returns flattened text comments.Move.GetCommand(key)still returns a single value for a command key.GetCommandreturns the last occurrence, matching the practical behavior of map-based overwrites.SetCommandupdates the last matching structured command when possible, or appends one if none exists.SetCommentintentionally resets structured comment blocks back to the legacy single flattened comment representation.AddCommentappends text while keeping structured comment state in sync.Breaking Changes
No source-level breaking change is intended.
Important behavior changes for PGN output:
CommentBlocks().Implementation Notes
CommentBlock/CommentItemvalues while parsing comments and command annotations.Tests
Added coverage for:
CommentBlocks()defensive-copy behaviorLocal verification:
go test ./...passes87.0%to89.0%locally after the added tests and dead-code simplification