Stream wrapper now contains instance of converter

This commit is contained in:
Andrew Golovashevich 2025-11-17 23:27:49 +03:00
parent a0b74a8ba6
commit 267e8fb82d

View File

@ -1,51 +1,53 @@
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
use source_stream_0::{CollectResult, CollectedSubstring, Pos, Predicate, SourceStream};
use source_stream_0::{CollectResult, CollectedSubstring, Keyword, Pos, Predicate, SourceStream};
use std::marker::PhantomData;
pub trait StreamConversions_Char<C> {
pub trait SourceStreamConverter_Char<C> {
type WC;
fn wrapChar(c: C) -> Self::WC;
}
pub trait StreamConversions_Pos<'pos, P: Pos<'pos>> {
pub trait StreamConverter_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>
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;
}
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>
pub trait StreamConverter<'source, 'pos, C, P: Pos<'pos>, CS: CollectedSubstring<'source, C = C>>:
SourceStreamConverter_Char<C>
+ StreamConverter_Pos<'pos, P>
+ StreamConverter_Substring<'source, C, CS>
{
}
struct PredicateWrapper<'predicate, C, W: StreamConversions_Char<C>, I: Predicate<W::WC>> {
struct PredicateWrapper<'predicate, 'converter, C, W: SourceStreamConverter_Char<C>, I: Predicate<W::WC>> {
_orig: &'predicate mut I,
__phantom: PhantomData<(C, W)>,
_converter: &'converter W,
__phantom: PhantomData<C>
}
impl<'predicate, C, W: StreamConversions_Char<C>, I: Predicate<W::WC>>
PredicateWrapper<'predicate, C, W, I>
impl<'predicate, 'converter, C, W: SourceStreamConverter_Char<C>, I: Predicate<W::WC>>
PredicateWrapper<'predicate, 'converter, C, W, I>
{
fn wrap(pred: &'predicate mut I) -> Self {
fn wrap(pred: &'predicate mut I, converter: &'converter W) -> Self {
return PredicateWrapper {
_orig: pred,
_converter: converter,
__phantom: PhantomData::default(),
};
}
}
impl<'predicate, C, W: StreamConversions_Char<C>, I: Predicate<W::WC>> Predicate<C>
for PredicateWrapper<'predicate, C, W, I>
impl<'predicate, 'converter, C, W: SourceStreamConverter_Char<C>, I: Predicate<W::WC>> Predicate<C>
for PredicateWrapper<'predicate, 'converter, C, W, I>
{
fn check(&mut self, chr: C) -> bool {
return self._orig.check(W::wrapChar(chr));
@ -58,10 +60,11 @@ pub struct SourceStreamWrapper<
C,
P: Pos<'pos>,
CS: CollectedSubstring<'source, C = C>,
W: StreamConversions<'source, 'pos, C, P, CS>,
W: StreamConverter<'source, 'pos, C, P, CS>,
I: SourceStream<'source, 'pos, C = C, P = P, CS = CS>,
> {
_src: I,
_converter: W,
__phantom: PhantomData<(&'source (), &'pos (), W)>,
}
@ -71,7 +74,7 @@ impl<
C,
P: Pos<'pos>,
CS: CollectedSubstring<'source, C = C>,
W: StreamConversions<'source, 'pos, C, P, CS>,
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>
{
@ -80,11 +83,11 @@ impl<
type CS = W::WCS;
fn skip(&mut self, predicate: &mut impl Predicate<W::WC>) -> bool {
self._src.skip(&mut PredicateWrapper::wrap(predicate))
self._src.skip(&mut PredicateWrapper::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)) {
match self._src.collect(&mut PredicateWrapper::wrap(predicate, &self._converter)) {
CollectResult::EOF => return CollectResult::EOF,
CollectResult::NotMatches => return CollectResult::NotMatches,
CollectResult::Matches(cs) => return CollectResult::Matches(W::wrapSubstring(cs)),