source-stream-0.rs/src/lib.rs

68 lines
1.8 KiB
Rust

#![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<C: Copy> {
fn check(&mut self, chr: C) -> bool;
}
pub trait KeywordComparatorIterator<'keyword, C> {
fn consume(&mut self, c: C) -> bool;
}
pub trait Keyword<C> {
fn startComparation<'keyword>(
&'keyword self,
expectedLen: usize,
) -> Option<impl KeywordComparatorIterator<'keyword, C>>;
}
pub trait CollectedSubstring<'source> {
type C;
fn compareKeyword<'keyword>(&self, kw: impl Keyword<Self::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>;
}