use pest::Span;
use pest::error::{Error as PestErr, ErrorVariant};
pub use pest::{iterators::Pair, Parser};
#[derive(Parser)]
#[grammar = "../grammar.pest"]
struct SDLP;
pub type Error = PestErr<Rule>;
pub type ParseRes<T> = Result<T, Error>;
pub type ParseTree<'input> = Pair<'input, Rule>;
pub fn parse_err(message: String, span: Span) -> Error {
Error::new_from_span(ErrorVariant::CustomError {message}, span)
}
pub fn parse(rule: Rule, input: &str) -> ParseRes<ParseTree> {
SDLP::parse(rule, input).map(|mut res| res.next().unwrap())
}