Renamed 'wrapper' -> 'converter'

This commit is contained in:
Andrew Golovashevich 2025-11-18 15:43:42 +03:00
parent 560848d186
commit fcb530425a
3 changed files with 32 additions and 29 deletions

View File

@ -4,6 +4,4 @@ edition = "2024"
[lib] [lib]
[dependencies] [dependencies]
source-stream-0 = { path = ".." }
source-stream-0-wrapper-0 = { path = "../wrapper" }

View File

@ -1,5 +1,5 @@
[package] [package]
name = "source-stream-0-wrapper-0" name = "source-stream-0-converter-0"
edition = "2024" edition = "2024"
[lib] [lib]

View File

@ -9,19 +9,19 @@ use std::marker::PhantomData;
pub trait SourceStreamConverter_Char<C> { pub trait SourceStreamConverter_Char<C> {
type WC; type WC;
fn wrapChar(c: C) -> Self::WC; fn convertChar(&self, c: C) -> Self::WC;
} }
pub trait StreamConverter_Pos<'pos, P: Pos<'pos>> { pub trait StreamConverter_Pos<'pos, P: Pos<'pos>> {
type WP: 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>>: pub trait StreamConverter_Substring<'source, C, CS: CollectedSubstring<'source, C = C>>:
SourceStreamConverter_Char<C> SourceStreamConverter_Char<C>
{ {
type WCS: CollectedSubstring<'source, C = Self::WC>; 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>>: 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, 'predicate,
'converter, 'converter,
C, C,
@ -44,10 +44,10 @@ struct PredicateWrapper<
} }
impl<'predicate, 'converter, C, W: SourceStreamConverter_Char<C>, I: Predicate<W::WC>> 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 { fn wrap(pred: &'predicate mut I, converter: &'converter W) -> Self {
return PredicateWrapper { return PredicateConverter {
_orig: pred, _orig: pred,
_converter: converter, _converter: converter,
__phantom: PhantomData::default(), __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> 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 { 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, 'source,
'pos, 'pos,
C, C,
@ -85,7 +85,7 @@ impl<
CS: CollectedSubstring<'source, C = C>, CS: CollectedSubstring<'source, C = C>,
W: StreamConverter<'source, 'pos, C, P, CS>, W: StreamConverter<'source, 'pos, C, P, CS>,
I: SourceStream<'source, 'pos, C = C, P = P, CS = 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 C = W::WC;
type P = W::WP; type P = W::WP;
@ -93,34 +93,39 @@ impl<
fn skip(&mut self, predicate: &mut impl Predicate<W::WC>) -> bool { fn skip(&mut self, predicate: &mut impl Predicate<W::WC>) -> bool {
self._src 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> { fn collect(&mut self, predicate: &mut impl Predicate<W::WC>) -> CollectResult<W::WCS> {
match self match self
._src ._src
.collect(&mut PredicateWrapper::wrap(predicate, &self._converter)) .collect(&mut PredicateConverter::wrap(predicate, &self._converter))
{ {
CollectResult::EOF => return CollectResult::EOF, CollectResult::EOF => return CollectResult::EOF,
CollectResult::NotMatches => return CollectResult::NotMatches, 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 { fn pos(&self) -> W::WP {
return W::wrapPos(self._src.pos()); return self._converter.convertPos(self._src.pos());
} }
fn currentChar(&self) -> Option<W::WC> { 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> { 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, 'keyword,
'converter, 'converter,
C, C,
@ -133,10 +138,10 @@ pub struct KeywordUnwrapper<
} }
impl<'keyword, 'converter, C, W: SourceStreamConverter_Char<C>, I: Keyword<W::WC>> 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 { fn unwrap(kw: &'keyword I, converter: &'converter W) -> Self {
return KeywordUnwrapper { return KeywordDeconverted {
_orig: kw, _orig: kw,
_converter: converter, _converter: converter,
__phantom: PhantomData::default(), __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> 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_>( fn startComparation<'self_>(
&'self_ self, &'self_ self,
@ -154,7 +159,7 @@ impl<'keyword, 'converter, C, W: SourceStreamConverter_Char<C>, I: Keyword<W::WC
return self return self
._orig ._orig
.startComparation(expectedLen) .startComparation(expectedLen)
.map(|it| KeywordComparatorWrapper { .map(|it| KeywordComparatorConverter {
_orig: it, _orig: it,
_converter: self._converter, _converter: self._converter,
__phantom: PhantomData::default(), __phantom: PhantomData::default(),
@ -162,7 +167,7 @@ impl<'keyword, 'converter, C, W: SourceStreamConverter_Char<C>, I: Keyword<W::WC
} }
} }
struct KeywordComparatorWrapper< struct KeywordComparatorConverter<
'keyword, 'keyword,
'converter, 'converter,
C, C,
@ -171,7 +176,7 @@ struct KeywordComparatorWrapper<
> { > {
_orig: I, _orig: I,
_converter: &'converter W, _converter: &'converter W,
__phantom: PhantomData<(&'keyword(), C)>, __phantom: PhantomData<(&'keyword (), C)>,
} }
impl< impl<
@ -181,9 +186,9 @@ impl<
W: SourceStreamConverter_Char<C>, W: SourceStreamConverter_Char<C>,
I: KeywordComparatorIterator<'keyword, W::WC>, I: KeywordComparatorIterator<'keyword, W::WC>,
> KeywordComparatorIterator<'keyword, C> > KeywordComparatorIterator<'keyword, C>
for KeywordComparatorWrapper<'keyword, 'converter, C, W, I> for KeywordComparatorConverter<'keyword, 'converter, C, W, I>
{ {
fn consume(&mut self, c: C) -> bool { fn consume(&mut self, c: C) -> bool {
todo!() self._orig.consume(self._converter.convertChar(c))
} }
} }