45 lines
1.3 KiB
Rust
45 lines
1.3 KiB
Rust
use crate::CollectedSubstring;
|
|
use crate::pos::Pos;
|
|
|
|
pub trait Predicate<C: Copy> {
|
|
fn check(&mut self, chr: C) -> bool;
|
|
}
|
|
|
|
pub trait SourceStream<'source, 'pos> {
|
|
type C: Copy;
|
|
type P: Pos<'pos>;
|
|
type CS: CollectedSubstring<'source, C = Self::C>;
|
|
|
|
fn skipNext(&mut self, predicate: &mut impl Predicate<Self::C>) -> Option<Self::C>;
|
|
|
|
fn skipCurrent(
|
|
&mut self,
|
|
current: Self::C,
|
|
predicate: &mut impl Predicate<Self::C>,
|
|
) -> Option<Self::C> {
|
|
if !predicate.check(current) {
|
|
return Some(current);
|
|
}
|
|
|
|
return self.skipNext(predicate);
|
|
}
|
|
|
|
/**
|
|
* Returns reference to a slice of the source which can be used for comparations
|
|
* and exporting (not standardized).
|
|
* Also returns char that failed predicate check for further
|
|
* interpretation or 'None' if the stream is ended.
|
|
*
|
|
* Predicate applied to char starting with next after current, assuming that current char
|
|
* already checked (you don't call this method in the blind, aren't you).
|
|
*
|
|
* Calling this method on ended stream (previous `nextChar` returned `None`)
|
|
* is undefined behavior.
|
|
*/
|
|
fn collect(&mut self, predicate: &mut impl Predicate<Self::C>) -> (Self::CS, Option<Self::C>);
|
|
|
|
fn pos(&self) -> Self::P;
|
|
|
|
fn nextChar(&mut self) -> Option<Self::C>;
|
|
}
|