use super::*;
#[derive(Debug, Copy, Clone, derive_more::Deref)]
#[allow(clippy::exhaustive_structs)]
pub struct StopAt<P: StopPredicate>(pub P);
pub trait StopPredicate: Copy {
fn stop_at(&self, kw: KeywordRef<'_>) -> bool;
}
impl<F: Copy + Fn(KeywordRef<'_>) -> bool> StopPredicate for F {
fn stop_at(&self, kw: KeywordRef<'_>) -> bool {
self(kw)
}
}
impl StopPredicate for bool {
fn stop_at(&self, _kw: KeywordRef<'_>) -> bool {
*self
}
}
#[macro_export]
macro_rules! stop_at { {} => {
$crate::parse2::internal_prelude::StopAt<
impl $crate::parse2::internal_prelude::StopPredicate
>
} }
impl StopAt<bool> {
pub fn doc_intro<D: NetdocParseable>() -> stop_at!() {
StopAt(D::is_intro_item_keyword)
}
}
#[derive(Debug, Copy, Clone)]
pub struct BitOrOutput<A, B>(A, B);
impl<A: StopPredicate, B: StopPredicate> std::ops::BitOr<StopAt<B>> for StopAt<A> {
type Output = StopAt<BitOrOutput<A, B>>;
fn bitor(self, rhs: StopAt<B>) -> Self::Output {
StopAt(BitOrOutput(self.0, rhs.0))
}
}
impl<A: StopPredicate, B: StopPredicate> StopPredicate for BitOrOutput<A, B> {
fn stop_at(&self, kw: KeywordRef<'_>) -> bool {
self.0.stop_at(kw) || self.1.stop_at(kw)
}
}