Wrapper stream stub
This commit is contained in:
parent
41dfb7f432
commit
4cd77ba975
8
wrapper/Cargo.toml
Normal file
8
wrapper/Cargo.toml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "source-stream-0-wrapper-0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
source-stream-0 = { path = ".." }
|
||||||
99
wrapper/src/lib.rs
Normal file
99
wrapper/src/lib.rs
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
#![allow(non_camel_case_types)]
|
||||||
|
#![allow(non_snake_case)]
|
||||||
|
|
||||||
|
use source_stream_0::{CollectResult, CollectedSubstring, Pos, Predicate, SourceStream};
|
||||||
|
|
||||||
|
pub trait StreamConversions_Char<C> {
|
||||||
|
type WC;
|
||||||
|
fn wrapChar(c: C) -> Self::WC;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait StreamConversions_Pos<'pos, P: Pos<'pos>> {
|
||||||
|
type WP: Pos<'pos>;
|
||||||
|
fn wrapPos(p: P) -> Self::WP;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait StreamConversions_Substring<'source, C, CS: CollectedSubstring<'source, C = C>>:
|
||||||
|
StreamConversions_Char<C>
|
||||||
|
{
|
||||||
|
type WCS: CollectedSubstring<'source, C = Self::WC>;
|
||||||
|
fn wrapSubstring(wcs: CS) -> Self::WCS;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait StreamConversions<'source, 'pos, C, P: Pos<'pos>, CS: CollectedSubstring<'source, C = C>>:
|
||||||
|
StreamConversions_Char<C> + StreamConversions_Pos<'pos, P> + StreamConversions_Substring<'source, C, CS>
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
struct PredicateWrapper<'predicate, I: Predicate> {
|
||||||
|
_orig: &'predicate mut I,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'predicate, C, W: StreamConversions_Char<C>, I: Predicate<C = W::WC>>
|
||||||
|
PredicateWrapper<'predicate, I>
|
||||||
|
{
|
||||||
|
fn wrap(pred: &'predicate mut I) -> Self {
|
||||||
|
return PredicateWrapper { _orig: pred };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'predicate, C, W: StreamConversions_Char<C>, I: Predicate<C = W::WC>> Predicate
|
||||||
|
for PredicateWrapper<'predicate, I>
|
||||||
|
{
|
||||||
|
type C = C;
|
||||||
|
|
||||||
|
fn check(&mut self, chr: C) -> bool {
|
||||||
|
return self._orig.check(W::wrapChar(chr));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct SourceStreamWrapper<
|
||||||
|
'source,
|
||||||
|
'pos,
|
||||||
|
C,
|
||||||
|
P: Pos<'pos>,
|
||||||
|
CS: CollectedSubstring<'source, C = C>,
|
||||||
|
W: StreamConversions<'source, 'pos, C, P, CS>,
|
||||||
|
I: SourceStream<'source, 'pos, C = C, P = P, CS = CS>,
|
||||||
|
> {
|
||||||
|
_src: I,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<
|
||||||
|
'source,
|
||||||
|
'pos,
|
||||||
|
C,
|
||||||
|
P: Pos<'pos>,
|
||||||
|
CS: CollectedSubstring<'source>,
|
||||||
|
W: StreamConversions<'source, 'pos, C, P, CS>,
|
||||||
|
I: SourceStream<'source, 'pos, C = C, P = P, CS = CS>,
|
||||||
|
> SourceStream<'source, 'pos> for SourceStreamWrapper<'source, 'pos, C, P, CS, W, I>
|
||||||
|
{
|
||||||
|
type C = W::WC;
|
||||||
|
type P = W::WP;
|
||||||
|
type CS = W::WCS;
|
||||||
|
|
||||||
|
fn skip(&mut self, predicate: &mut impl Predicate<C = W::WC>) -> bool {
|
||||||
|
self._src.skip(&mut PredicateWrapper::wrap(predicate))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn collect(&mut self, predicate: &mut impl Predicate<C = W::WC>) -> CollectResult<W::WCS> {
|
||||||
|
match self._src.collect(&mut PredicateWrapper::wrap(predicate)) {
|
||||||
|
CollectResult::EOF => return CollectResult::EOF,
|
||||||
|
CollectResult::NotMatches => return CollectResult::NotMatches,
|
||||||
|
CollectResult::Matches(cs) => return CollectResult::Matches(W::wrapSubstring(cs)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn pos(&self) -> W::WP {
|
||||||
|
return W::wrapPos(self._src.pos());
|
||||||
|
}
|
||||||
|
|
||||||
|
fn currentChar(&self) -> Option<W::WC> {
|
||||||
|
return self._src.currentChar().map(W::wrapChar);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn nextChar(&mut self) -> Option<W::WC> {
|
||||||
|
return self._src.nextChar().map(W::wrapChar);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user