The module also provides a denial-of-service resistant streaming parser.
It can be configured with a budget for reasonable complexity of a single
game, fed with chunks of text, and will yield parsed games as they are
completed.
You can use walk to visit all nodes in the game tree, or transform
to augment it with user data.
Both allow you to provide context. You update the context inside the
callback, and it is automatically clone()-ed at each fork.
In the example below, the current position pos is provided as context.
Parse, transform and write PGN.
Parser
The parser will interpret any input as a PGN, creating a tree of syntactically valid (but not necessarily legal) moves, skipping any invalid tokens.
Streaming parser
The module also provides a denial-of-service resistant streaming parser. It can be configured with a budget for reasonable complexity of a single game, fed with chunks of text, and will yield parsed games as they are completed.
Augmenting the game tree
You can use
walk
to visit all nodes in the game tree, ortransform
to augment it with user data.Both allow you to provide context. You update the context inside the callback, and it is automatically
clone()
-ed at each fork. In the example below, the current positionpos
is provided as context.Writing
Requires each node to at least have a
san
property.