Closed julianandrews closed 3 years ago
Importantly - SgfNodeBuilder
wouldn't make any effort to force the intermediate stages to be valid SGF. Validation would happen only on calls to build
. It would also make sense to add an is_valid
method to the builder, to allow checking the state in the middle of the process.
All done!
Currently
SgfNode
is immutable, and validates that all SGF specification requirements are met. This has a lot to recommend it, but it does mean that editing an SGF requires either lots of cloning, or destructuring and rebuilding.Adding the functionality to modify an
SgfNode
would be work intensive and complicate the interface substantially. I want to keep that simple and immutable. Instead, I can add anSgfNodeBuilder
struct with public fields that allows direct and easy access to the internals. This struct can then have abuild
method that validates the entire tree and returns the root immutable node. AnSgfNode
would also have ato_builder
method which consumes theSgfNode
and its children, and returns anSgfNodeBuilder
.