feat: preserve PGN annotation structure#117
Draft
CorentinGS wants to merge 1 commit into
Draft
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #117 +/- ##
==========================================
+ Coverage 70.32% 72.18% +1.85%
==========================================
Files 27 27
Lines 4186 4257 +71
==========================================
+ Hits 2944 3073 +129
+ Misses 1110 1065 -45
+ Partials 132 119 -13 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
d76a3b1 to
fdd76b9
Compare
fdd76b9 to
60f222b
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