Add support for pre-move comments in GameNode and StringExporter #1173
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.
This PR adds a
pre_commentattribute toGameNodeand updates theStringExporterto support writing comments immediately before a move token.Use Case:
In many educational chess materials (and complex PGNs), there is a semantic difference between a comment explaining the previous position and a comment giving instructions specifically for the upcoming move (e.g., "Find the best move").
Currently, users are forced to append such comments to
node.parent.comment, which works for PGN validity but loses the logical association in the object model.Changes:
pre_commentattribute toGameNode.visit_pre_commenttoBaseVisitorandStringExporterMixin.ChildNode._accept_nodeto visit the pre-comment before the move.This implementation ensures that
force_movenumberis triggered after a pre-comment, producing valid PGN output like:1. e4 {Post-comment} {Pre-comment for next move} 2. Nf3