2024-02-16 14:02:50 -06:00
|
|
|
//@ build-pass
|
|
|
|
//@ compile-flags: --crate-type=lib
|
2023-04-04 05:39:26 -05:00
|
|
|
|
|
|
|
use std::marker::PhantomData;
|
|
|
|
|
|
|
|
pub trait StreamOnce {
|
|
|
|
type Token;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl StreamOnce for &str {
|
|
|
|
type Token = ();
|
|
|
|
}
|
|
|
|
|
|
|
|
pub trait Parser<Input: StreamOnce> {
|
|
|
|
type PartialState: Default;
|
|
|
|
fn parse_mode(&self, _state: &Self::PartialState) {}
|
|
|
|
fn parse_mode_impl() {}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn parse_bool<'a>() -> impl Parser<&'a str> {
|
|
|
|
pub struct TokensCmp<C, Input>
|
|
|
|
where
|
|
|
|
Input: StreamOnce,
|
|
|
|
{
|
|
|
|
_cmp: C,
|
|
|
|
_marker: PhantomData<Input>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<Input, C> Parser<Input> for TokensCmp<C, Input>
|
|
|
|
where
|
|
|
|
C: FnMut(Input::Token),
|
|
|
|
Input: StreamOnce,
|
|
|
|
{
|
|
|
|
type PartialState = ();
|
|
|
|
}
|
|
|
|
|
|
|
|
TokensCmp { _cmp: |_| (), _marker: PhantomData }
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct ParseBool;
|
|
|
|
|
|
|
|
impl<'a> Parser<&'a str> for ParseBool
|
|
|
|
where
|
|
|
|
&'a str: StreamOnce,
|
|
|
|
{
|
|
|
|
type PartialState = ();
|
|
|
|
|
|
|
|
fn parse_mode_impl() {
|
|
|
|
parse_bool().parse_mode(&Default::default())
|
|
|
|
}
|
|
|
|
}
|