use super::{Location};
pub struct Invalid;
impl From<()> for Invalid {
fn from(_: ()) -> Self { Self }
}
pub trait AST: Sized + std::fmt::Debug {
type Generous;
fn validate(report: &mut impl FnMut(Location, &str), tree: &Self::Generous)
-> Result<Self, Invalid>;
}
impl<T: AST> AST for Option<T> {
type Generous = Option<T::Generous>;
fn validate(report: &mut impl FnMut(Location, &str), tree: &Self::Generous)
-> Result<Self, Invalid> {
Ok(if let Some(tree) = tree {
Some(T::validate(report, tree)?)
} else {
None
})
}
}
impl<T: AST> AST for Box<T> {
type Generous = Box<T::Generous>;
fn validate(report: &mut impl FnMut(Location, &str), tree: &Self::Generous)
-> Result<Self, Invalid> {
Ok(Box::new(T::validate(report, tree)?))
}
}