50 lines
1.1 KiB
Rust
50 lines
1.1 KiB
Rust
mod _keyword_impls;
|
|
mod parser_func;
|
|
|
|
pub trait Predicate<C> {
|
|
fn check(&mut self, chr: C) -> bool;
|
|
}
|
|
|
|
pub trait Pos<'pos> {}
|
|
|
|
impl Pos<'static> for () {}
|
|
impl Pos<'static> for usize {}
|
|
|
|
pub trait KeywordComparatorIterator<'keyword, C> {
|
|
fn consume(&mut self, c: C) -> bool;
|
|
}
|
|
|
|
pub trait Keyword<'keyword, C> {
|
|
fn startComparation(
|
|
&self,
|
|
expectedLen: usize,
|
|
) -> Option<impl KeywordComparatorIterator<'keyword, C>>;
|
|
}
|
|
|
|
pub trait CollectedSubstring<'source, C> {
|
|
fn compareKeyword<'keyword>(&self, kw: impl Keyword<'keyword, C>) -> bool;
|
|
}
|
|
|
|
pub enum CollectResult<T> {
|
|
EOF,
|
|
NotMatches,
|
|
Matches(T),
|
|
}
|
|
|
|
pub trait SourceStream<'source, 'pos, C, P: Pos<'pos>, CS: CollectedSubstring<'source, C>> {
|
|
/**
|
|
* Returns `true` if the end of stream reached.
|
|
*/
|
|
fn skip(&mut self, predicate: &mut impl Predicate<C>) -> bool;
|
|
fn collect(&mut self, predicate: &mut impl Predicate<C>) -> CollectResult<CS>;
|
|
|
|
fn pos(&self) -> P;
|
|
|
|
fn currentChar(&self) -> Option<C>;
|
|
fn nextChar(&mut self) -> Option<C>;
|
|
|
|
fn isEnded(&mut self) -> bool {
|
|
return self.currentChar().is_none();
|
|
}
|
|
}
|