#![allow(non_snake_case)] mod _keyword_impls; mod macros; mod default_streams; mod ascii; pub mod pos; pub mod converter; use pos::Pos; pub trait Predicate { fn check(&mut self, chr: C) -> bool; } pub trait KeywordComparatorIterator<'keyword, C> { fn consume(&mut self, c: C) -> bool; } pub trait Keyword { fn startComparation<'keyword>( &'keyword self, expectedLen: usize, ) -> Option>; } pub trait CollectedSubstring<'source> { type C; fn compareKeyword<'keyword>(&self, kw: impl Keyword) -> 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; }