63 lines
1.5 KiB
Rust
63 lines
1.5 KiB
Rust
use std::marker::PhantomData;
|
|
use crate::{CollectedSubstring, Pos, Predicate, SourceStream};
|
|
use crate::pos::PosCounter;
|
|
|
|
pub struct EmptySourceStream<
|
|
'source,
|
|
'pos,
|
|
C: Copy,
|
|
P: Pos<'pos>,
|
|
CS: CollectedSubstring<'source, C=C>,
|
|
PC: PosCounter<'pos, C, P=P>,
|
|
> {
|
|
_pos: PC,
|
|
__phantom: PhantomData<(&'source (), &'pos (), P, CS)>,
|
|
}
|
|
impl<
|
|
'source,
|
|
'pos,
|
|
C: Copy,
|
|
P: Pos<'pos>,
|
|
CS: CollectedSubstring<'source, C=C>,
|
|
PC: PosCounter<'pos, C, P=P>,
|
|
> EmptySourceStream<'source, 'pos, C, P, CS, PC>
|
|
{
|
|
pub fn start(pos: PC) -> (Self, Option<C>) {
|
|
let stream = EmptySourceStream {
|
|
_pos: pos,
|
|
__phantom: PhantomData::default()
|
|
};
|
|
return (stream, None);
|
|
}
|
|
}
|
|
|
|
impl<
|
|
'source,
|
|
'pos,
|
|
C: Copy,
|
|
P: Pos<'pos>,
|
|
CS: CollectedSubstring<'source, C=C>,
|
|
PC: PosCounter<'pos, C, P=P>,
|
|
> SourceStream<'source, 'pos> for EmptySourceStream<'source, 'pos, C, P, CS, PC>
|
|
{
|
|
type C = C;
|
|
type P = P;
|
|
type CS = CS;
|
|
|
|
fn skipNext(&mut self, predicate: &mut impl Predicate<Self::C>) -> Option<Self::C> {
|
|
return None;
|
|
}
|
|
|
|
fn collect(&mut self, predicate: &mut impl Predicate<Self::C>) -> (Self::CS, Option<Self::C>) {
|
|
panic!("How about to check first char of substring being collected first");
|
|
}
|
|
|
|
fn pos(&self) -> Self::P {
|
|
return self._pos.export();
|
|
}
|
|
|
|
fn nextChar(&mut self) -> Option<Self::C> {
|
|
return None;
|
|
}
|
|
}
|