sgf-parser

Crates.iosgf-parser
lib.rssgf-parser
version2.6.0
sourcesrc
created_at2018-12-19 20:55:28.846832
updated_at2021-01-21 08:05:50.029456
descriptionA library for parsing SGF files
homepage
repositoryhttps://github.com/mipli/sgf-parser
max_upload_size
id102803
size86,211
Michael (mipli)

documentation

https://docs.rs/sgf-parser/latest/sgf-parser/

README

Build Status Crate Docs

SGF Parser

A SGF Parser for Rust. Supports all SGF properties, and tree branching.

NOTE when converting a GameTree to a string we convert all charset tokens to be UTF-8, since that is the encoding for all strings in Rust.

Using pest for the actual parsing part.

Development

Code quality is ensured by running both cargo clippy and cargo fmt on each commit.

All code should also be unit tested.

Example usage

use sgf_parser::*;

let sgf_source = "(;C[comment]EV[event]PB[black]PW[white];B[aa])";
let tree: Result<GameTree, SgfError> = parse(sgf_source);

let tree = tree.unwrap();
let unknown_nodes = tree.get_unknown_nodes();
assert_eq!(unknown_nodes.len(), 0);

let invalid_nodes = tree.get_invalid_nodes();
assert_eq!(invalid_nodes.len(), 0);

tree.iter().for_each(|node| {
  assert!(!node.tokens.is_empty());
});

let sgf_string: String = tree.into();
assert_eq!(sgf_source, sgf_string());
Commit count: 59

cargo fmt