use std::fmt;
use pest::Span;
use pest::error::{Error, ErrorVariant};
use super::Rule;
#[derive(Debug, Clone)]
pub struct ParseError(Error<Rule>);
impl ParseError {
pub(crate) fn at_span(span: Span<'_>, message: impl Into<String>) -> Self {
Self(Error::new_from_span(
ErrorVariant::CustomError {
message: message.into(),
},
span,
))
}
#[must_use]
pub fn into_inner(self) -> Error<Rule> {
self.0
}
}
impl From<Error<Rule>> for ParseError {
fn from(error: Error<Rule>) -> Self {
Self(error)
}
}
impl fmt::Display for ParseError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Display::fmt(&self.0, f)
}
}
impl std::error::Error for ParseError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
Some(&self.0)
}
}