use crate::{Cursor, KindSet, Parser};
pub trait Peek<'a>: Sized {
const PEEK_KINDSET: KindSet = KindSet::ANY;
fn peek<I>(_: &Parser<'a, I>, c: Cursor) -> bool
where
I: Iterator<Item = Cursor> + Clone,
{
c == Self::PEEK_KINDSET
}
}
impl<'a, T: Peek<'a>> Peek<'a> for Option<T> {
fn peek<I>(p: &Parser<'a, I>, c: Cursor) -> bool
where
I: Iterator<Item = Cursor> + Clone,
{
T::peek(p, c)
}
}
impl<'a, T: Peek<'a>> Peek<'a> for ::bumpalo::collections::Vec<'a, T> {
const PEEK_KINDSET: KindSet = T::PEEK_KINDSET;
fn peek<I>(p: &Parser<'a, I>, c: Cursor) -> bool
where
I: Iterator<Item = Cursor> + Clone,
{
T::peek(p, c)
}
}
macro_rules! impl_tuple {
($($T:ident),*) => {
impl<'a, $($T),*> Peek<'a> for ($($T),*)
where
$($T: Peek<'a>,)*
{
fn peek<Iter>(p: &Parser<'a, Iter>, c: Cursor) -> bool
where
Iter: Iterator<Item = Cursor> + Clone,
{
A::peek(p, c)
}
}
};
}
impl_tuple!(A, B);
impl_tuple!(A, B, C);
impl_tuple!(A, B, C, D);
impl_tuple!(A, B, C, D, E);
impl_tuple!(A, B, C, D, E, F);
impl_tuple!(A, B, C, D, E, F, G);
impl_tuple!(A, B, C, D, E, F, G, H);
impl_tuple!(A, B, C, D, E, F, G, H, I);
impl_tuple!(A, B, C, D, E, F, G, H, I, J);
impl_tuple!(A, B, C, D, E, F, G, H, I, J, K);
impl_tuple!(A, B, C, D, E, F, G, H, I, J, K, L);