Renamed 'wrapper' -> 'converter'
This commit is contained in:
parent
560848d186
commit
fcb530425a
@ -4,6 +4,4 @@ edition = "2024"
|
||||
|
||||
[lib]
|
||||
|
||||
[dependencies]
|
||||
source-stream-0 = { path = ".." }
|
||||
source-stream-0-wrapper-0 = { path = "../wrapper" }
|
||||
[dependencies]
|
||||
@ -1,5 +1,5 @@
|
||||
[package]
|
||||
name = "source-stream-0-wrapper-0"
|
||||
name = "source-stream-0-converter-0"
|
||||
edition = "2024"
|
||||
|
||||
[lib]
|
||||
@ -9,19 +9,19 @@ use std::marker::PhantomData;
|
||||
|
||||
pub trait SourceStreamConverter_Char<C> {
|
||||
type WC;
|
||||
fn wrapChar(c: C) -> Self::WC;
|
||||
fn convertChar(&self, c: C) -> Self::WC;
|
||||
}
|
||||
|
||||
pub trait StreamConverter_Pos<'pos, P: Pos<'pos>> {
|
||||
type WP: Pos<'pos>;
|
||||
fn wrapPos(p: P) -> Self::WP;
|
||||
fn convertPos(&self, p: P) -> Self::WP;
|
||||
}
|
||||
|
||||
pub trait StreamConverter_Substring<'source, C, CS: CollectedSubstring<'source, C = C>>:
|
||||
SourceStreamConverter_Char<C>
|
||||
{
|
||||
type WCS: CollectedSubstring<'source, C = Self::WC>;
|
||||
fn wrapSubstring(wcs: CS) -> Self::WCS;
|
||||
fn convertSubstring(&self, wcs: CS) -> Self::WCS;
|
||||
}
|
||||
|
||||
pub trait StreamConverter<'source, 'pos, C, P: Pos<'pos>, CS: CollectedSubstring<'source, C = C>>:
|
||||
@ -31,7 +31,7 @@ pub trait StreamConverter<'source, 'pos, C, P: Pos<'pos>, CS: CollectedSubstring
|
||||
{
|
||||
}
|
||||
|
||||
struct PredicateWrapper<
|
||||
struct PredicateConverter<
|
||||
'predicate,
|
||||
'converter,
|
||||
C,
|
||||
@ -44,10 +44,10 @@ struct PredicateWrapper<
|
||||
}
|
||||
|
||||
impl<'predicate, 'converter, C, W: SourceStreamConverter_Char<C>, I: Predicate<W::WC>>
|
||||
PredicateWrapper<'predicate, 'converter, C, W, I>
|
||||
PredicateConverter<'predicate, 'converter, C, W, I>
|
||||
{
|
||||
fn wrap(pred: &'predicate mut I, converter: &'converter W) -> Self {
|
||||
return PredicateWrapper {
|
||||
return PredicateConverter {
|
||||
_orig: pred,
|
||||
_converter: converter,
|
||||
__phantom: PhantomData::default(),
|
||||
@ -56,14 +56,14 @@ impl<'predicate, 'converter, C, W: SourceStreamConverter_Char<C>, I: Predicate<W
|
||||
}
|
||||
|
||||
impl<'predicate, 'converter, C, W: SourceStreamConverter_Char<C>, I: Predicate<W::WC>> Predicate<C>
|
||||
for PredicateWrapper<'predicate, 'converter, C, W, I>
|
||||
for PredicateConverter<'predicate, 'converter, C, W, I>
|
||||
{
|
||||
fn check(&mut self, chr: C) -> bool {
|
||||
return self._orig.check(W::wrapChar(chr));
|
||||
return self._orig.check(self._converter.convertChar(chr));
|
||||
}
|
||||
}
|
||||
|
||||
pub struct SourceStreamWrapper<
|
||||
pub struct ConvertedSourceStream<
|
||||
'source,
|
||||
'pos,
|
||||
C,
|
||||
@ -85,7 +85,7 @@ impl<
|
||||
CS: CollectedSubstring<'source, C = C>,
|
||||
W: StreamConverter<'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>
|
||||
> SourceStream<'source, 'pos> for ConvertedSourceStream<'source, 'pos, C, P, CS, W, I>
|
||||
{
|
||||
type C = W::WC;
|
||||
type P = W::WP;
|
||||
@ -93,34 +93,39 @@ impl<
|
||||
|
||||
fn skip(&mut self, predicate: &mut impl Predicate<W::WC>) -> bool {
|
||||
self._src
|
||||
.skip(&mut PredicateWrapper::wrap(predicate, &self._converter))
|
||||
.skip(&mut PredicateConverter::wrap(predicate, &self._converter))
|
||||
}
|
||||
|
||||
fn collect(&mut self, predicate: &mut impl Predicate<W::WC>) -> CollectResult<W::WCS> {
|
||||
match self
|
||||
._src
|
||||
.collect(&mut PredicateWrapper::wrap(predicate, &self._converter))
|
||||
.collect(&mut PredicateConverter::wrap(predicate, &self._converter))
|
||||
{
|
||||
CollectResult::EOF => return CollectResult::EOF,
|
||||
CollectResult::NotMatches => return CollectResult::NotMatches,
|
||||
CollectResult::Matches(cs) => return CollectResult::Matches(W::wrapSubstring(cs)),
|
||||
CollectResult::Matches(cs) => {
|
||||
return CollectResult::Matches(self._converter.convertSubstring(cs));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn pos(&self) -> W::WP {
|
||||
return W::wrapPos(self._src.pos());
|
||||
return self._converter.convertPos(self._src.pos());
|
||||
}
|
||||
|
||||
fn currentChar(&self) -> Option<W::WC> {
|
||||
return self._src.currentChar().map(W::wrapChar);
|
||||
return self
|
||||
._src
|
||||
.currentChar()
|
||||
.map(|c| self._converter.convertChar(c));
|
||||
}
|
||||
|
||||
fn nextChar(&mut self) -> Option<W::WC> {
|
||||
return self._src.nextChar().map(W::wrapChar);
|
||||
return self._src.nextChar().map(|c| self._converter.convertChar(c));
|
||||
}
|
||||
}
|
||||
|
||||
pub struct KeywordUnwrapper<
|
||||
pub struct KeywordDeconverted<
|
||||
'keyword,
|
||||
'converter,
|
||||
C,
|
||||
@ -133,10 +138,10 @@ pub struct KeywordUnwrapper<
|
||||
}
|
||||
|
||||
impl<'keyword, 'converter, C, W: SourceStreamConverter_Char<C>, I: Keyword<W::WC>>
|
||||
KeywordUnwrapper<'keyword, 'converter, C, W, I>
|
||||
KeywordDeconverted<'keyword, 'converter, C, W, I>
|
||||
{
|
||||
fn unwrap(kw: &'keyword I, converter: &'converter W) -> Self {
|
||||
return KeywordUnwrapper {
|
||||
return KeywordDeconverted {
|
||||
_orig: kw,
|
||||
_converter: converter,
|
||||
__phantom: PhantomData::default(),
|
||||
@ -145,7 +150,7 @@ impl<'keyword, 'converter, C, W: SourceStreamConverter_Char<C>, I: Keyword<W::WC
|
||||
}
|
||||
|
||||
impl<'keyword, 'converter, C, W: SourceStreamConverter_Char<C>, I: Keyword<W::WC>> Keyword<C>
|
||||
for KeywordUnwrapper<'keyword, 'converter, C, W, I>
|
||||
for KeywordDeconverted<'keyword, 'converter, C, W, I>
|
||||
{
|
||||
fn startComparation<'self_>(
|
||||
&'self_ self,
|
||||
@ -154,7 +159,7 @@ impl<'keyword, 'converter, C, W: SourceStreamConverter_Char<C>, I: Keyword<W::WC
|
||||
return self
|
||||
._orig
|
||||
.startComparation(expectedLen)
|
||||
.map(|it| KeywordComparatorWrapper {
|
||||
.map(|it| KeywordComparatorConverter {
|
||||
_orig: it,
|
||||
_converter: self._converter,
|
||||
__phantom: PhantomData::default(),
|
||||
@ -162,7 +167,7 @@ impl<'keyword, 'converter, C, W: SourceStreamConverter_Char<C>, I: Keyword<W::WC
|
||||
}
|
||||
}
|
||||
|
||||
struct KeywordComparatorWrapper<
|
||||
struct KeywordComparatorConverter<
|
||||
'keyword,
|
||||
'converter,
|
||||
C,
|
||||
@ -171,7 +176,7 @@ struct KeywordComparatorWrapper<
|
||||
> {
|
||||
_orig: I,
|
||||
_converter: &'converter W,
|
||||
__phantom: PhantomData<(&'keyword(), C)>,
|
||||
__phantom: PhantomData<(&'keyword (), C)>,
|
||||
}
|
||||
|
||||
impl<
|
||||
@ -181,9 +186,9 @@ impl<
|
||||
W: SourceStreamConverter_Char<C>,
|
||||
I: KeywordComparatorIterator<'keyword, W::WC>,
|
||||
> KeywordComparatorIterator<'keyword, C>
|
||||
for KeywordComparatorWrapper<'keyword, 'converter, C, W, I>
|
||||
for KeywordComparatorConverter<'keyword, 'converter, C, W, I>
|
||||
{
|
||||
fn consume(&mut self, c: C) -> bool {
|
||||
todo!()
|
||||
self._orig.consume(self._converter.convertChar(c))
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user