use super::*;
pub trait PeekerItem: Sized {
fn from_tok(token: Token) -> Option<Self>;
}
impl PeekerItem for String {
fn from_tok(token: Token) -> Option<Self> {
if let Token::Str(s) = token {
Some(s)
} else {
None
}
}
}
pub trait Peeker {
type Item: PeekerItem;
fn peek_for_token(&self, parser: &mut Parser) -> Option<Token>;
fn peek_for(&self, parser: &mut Parser) -> Option<Self::Item> {
Self::Item::from_tok(
self.peek_for_token(parser)?
)
}
}
pub trait IsContainerCpInput {}
pub trait ContainedType {}
pub trait ContainerCp {
type Input: IsContainerCpInput;
type ContainedType: ContainedType;
fn new_contained(value: Self::Input) -> Self::ContainedType;
fn new(value: Self::Input) -> Self;
}
pub trait ConcreteParser: Peeker + ContainerCp {
fn try_next_token(&self, parser: &mut Parser) -> Option<Token>;
fn try_next(&self, parser: &mut Parser) -> Option<Self::Item> {
Self::Item::from_tok(
self.try_next_token(parser)?
)
}
}
impl<T> ConcreteParser for T
where
T: Peeker + ContainerCp
{
fn try_next_token(&self, parser: &mut Parser) -> Option<Token> {
if let Some(tok) = self.peek_for_token(parser) {
parser.next();
Some(tok)
} else {
None
}
}
}
impl IsContainerCpInput for String {}
impl ContainedType for String {}
impl IsContainerCpInput for () {}
impl ContainedType for () {}
mod exact_match;
mod or_exact_match;
mod any_str_match;
mod is_newline;
mod is_tab;
pub mod list {
pub use super::{
exact_match::ExactMatch,
or_exact_match::OrExactMatch,
any_str_match::AnyStrMatch,
is_newline::IsNewline,
is_tab::IsTab
};
}