2023-07-26 01:08:22 +00:00
|
|
|
mod date;
|
|
|
|
pub use date::Date;
|
|
|
|
|
2023-10-19 07:02:37 +00:00
|
|
|
mod parser;
|
|
|
|
pub use parser::parse_collection;
|
2023-06-22 14:04:52 +00:00
|
|
|
|
|
|
|
use thiserror::Error;
|
|
|
|
|
2023-10-19 06:43:08 +00:00
|
|
|
mod types;
|
|
|
|
pub use types::*;
|
|
|
|
|
2023-07-26 23:33:50 +00:00
|
|
|
#[derive(Debug)]
|
2023-07-27 00:15:22 +00:00
|
|
|
pub enum Error {
|
2023-07-26 23:33:50 +00:00
|
|
|
InvalidField,
|
|
|
|
InvalidBoardSize,
|
|
|
|
Incomplete,
|
2023-07-27 00:15:22 +00:00
|
|
|
InvalidSgf(VerboseNomError),
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct VerboseNomError(nom::error::VerboseError<String>);
|
|
|
|
|
|
|
|
impl From<nom::error::VerboseError<&str>> for VerboseNomError {
|
|
|
|
fn from(err: nom::error::VerboseError<&str>) -> Self {
|
|
|
|
VerboseNomError(nom::error::VerboseError {
|
|
|
|
errors: err
|
|
|
|
.errors
|
|
|
|
.into_iter()
|
|
|
|
.map(|err| (err.0.to_owned(), err.1))
|
|
|
|
.collect(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<nom::Err<nom::error::VerboseError<&str>>> for Error {
|
|
|
|
fn from(err: nom::Err<nom::error::VerboseError<&str>>) -> Self {
|
|
|
|
match err {
|
|
|
|
nom::Err::Incomplete(_) => Error::Incomplete,
|
|
|
|
nom::Err::Error(e) => Error::InvalidSgf(VerboseNomError::from(e)),
|
|
|
|
nom::Err::Failure(e) => Error::InvalidSgf(VerboseNomError::from(e)),
|
|
|
|
}
|
|
|
|
}
|
2023-07-26 23:33:50 +00:00
|
|
|
}
|
2023-06-22 14:04:52 +00:00
|
|
|
|
|
|
|
#[derive(Debug, PartialEq, Error)]
|
|
|
|
pub enum ParseError {
|
|
|
|
#[error("An unknown error was found")]
|
2023-06-23 13:46:05 +00:00
|
|
|
NomError(nom::error::Error<String>),
|
2023-06-22 14:04:52 +00:00
|
|
|
}
|
|
|
|
|
2023-06-23 03:58:16 +00:00
|
|
|
impl From<nom::error::Error<&str>> for ParseError {
|
2023-06-23 13:46:05 +00:00
|
|
|
fn from(err: nom::error::Error<&str>) -> Self {
|
|
|
|
Self::NomError(nom::error::Error {
|
|
|
|
input: err.input.to_owned(),
|
2023-10-05 15:41:00 +00:00
|
|
|
code: err.code,
|
2023-06-23 13:46:05 +00:00
|
|
|
})
|
2023-06-23 03:58:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-19 06:43:08 +00:00
|
|
|
pub fn parse_sgf(_input: &str) -> Result<Vec<Game>, Error> {
|
|
|
|
Ok(vec![Game::default()])
|
2023-06-23 13:46:05 +00:00
|
|
|
}
|