use crate::CollectedSubstring; use crate::pos::Pos; pub trait Predicate { 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) -> Option; fn skipCurrent( &mut self, current: Self::C, predicate: &mut impl Predicate, ) -> Option { 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::CS, Option); fn pos(&self) -> Self::P; fn nextChar(&mut self) -> Option; }