sgf_parser/lib.rs
1//! # SGF Parser for Rust
2//!
3//! A sgf parser for rust. Supports all SGF properties, and tree branching.
4//!
5//! Using `pest` for the actual parsing part.
6//!
7//! NOTE: when converting a `GameTree` to a string we convert all charset tokens to be UTF-8, since
8//! that is the encoding for all strings in Rust.
9//!
10//! # Example usage
11//! ```rust
12//! use sgf_parser::*;
13//!
14//! let sgf_source = "(;C[comment]EV[event]PB[black]PW[white];B[aa])";
15//! let tree: Result<GameTree, SgfError> = parse(sgf_source);
16//!
17//! let tree = tree.unwrap();
18//! let unknown_nodes = tree.get_unknown_nodes();
19//! assert_eq!(unknown_nodes.len(), 0);
20//!
21//! let invalid_nodes = tree.get_invalid_nodes();
22//! assert_eq!(invalid_nodes.len(), 0);
23//!
24//! tree.iter().for_each(|node| {
25//! assert!(!node.tokens.is_empty());
26//! });
27//!
28//! let sgf_string: String = tree.into();
29//! assert_eq!(sgf_source, sgf_string);
30//! ```
31#![deny(rust_2018_idioms)]
32
33mod error;
34mod node;
35mod parser;
36mod token;
37mod tree;
38
39pub use crate::error::{SgfError, SgfErrorKind};
40pub use crate::node::GameNode;
41pub use crate::parser::parse;
42pub use crate::token::{Action, Color, DisplayNodes, Encoding, Game, Outcome, RuleSet, SgfToken};
43pub use crate::tree::GameTree;