10 releases (6 stable)

✓ Uses Rust 2018 edition

new 2.4.0 Jan 24, 2020
2.3.0 Sep 18, 2019
1.0.0 Apr 29, 2019
0.4.0 Apr 14, 2019
0.1.0 Dec 19, 2018

#97 in Parser tooling

Download history 27/week @ 2019-10-13 19/week @ 2019-10-20 40/week @ 2019-10-27 12/week @ 2019-11-03 1/week @ 2019-11-10 41/week @ 2019-11-17 21/week @ 2019-11-24 20/week @ 2019-12-01 779/week @ 2019-12-08 24/week @ 2019-12-15 23/week @ 2019-12-22 10/week @ 2019-12-29 24/week @ 2020-01-05 39/week @ 2020-01-12 37/week @ 2020-01-19

354 downloads per month
Used in goban

MIT license

44KB
982 lines

Build Status Crate

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());

Dependencies

~2MB
~37K SLoC