Stream wrapper now contains instance of converter
This commit is contained in:
parent
a0b74a8ba6
commit
267e8fb82d
@ -1,51 +1,53 @@
|
|||||||
#![allow(non_camel_case_types)]
|
#![allow(non_camel_case_types)]
|
||||||
#![allow(non_snake_case)]
|
#![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;
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
pub trait StreamConversions_Char<C> {
|
pub trait SourceStreamConverter_Char<C> {
|
||||||
type WC;
|
type WC;
|
||||||
fn wrapChar(c: C) -> Self::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>;
|
type WP: Pos<'pos>;
|
||||||
fn wrapPos(p: P) -> Self::WP;
|
fn wrapPos(p: P) -> Self::WP;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait StreamConversions_Substring<'source, C, CS: CollectedSubstring<'source, C = C>>:
|
pub trait StreamConverter_Substring<'source, C, CS: CollectedSubstring<'source, C = C>>:
|
||||||
StreamConversions_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 wrapSubstring(wcs: CS) -> Self::WCS;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait StreamConversions<'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>>:
|
||||||
StreamConversions_Char<C>
|
SourceStreamConverter_Char<C>
|
||||||
+ StreamConversions_Pos<'pos, P>
|
+ StreamConverter_Pos<'pos, P>
|
||||||
+ StreamConversions_Substring<'source, C, CS>
|
+ 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,
|
_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>>
|
impl<'predicate, 'converter, C, W: SourceStreamConverter_Char<C>, I: Predicate<W::WC>>
|
||||||
PredicateWrapper<'predicate, C, W, I>
|
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 {
|
return PredicateWrapper {
|
||||||
_orig: pred,
|
_orig: pred,
|
||||||
|
_converter: converter,
|
||||||
__phantom: PhantomData::default(),
|
__phantom: PhantomData::default(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'predicate, C, W: StreamConversions_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, C, W, I>
|
for PredicateWrapper<'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(W::wrapChar(chr));
|
||||||
@ -58,10 +60,11 @@ pub struct SourceStreamWrapper<
|
|||||||
C,
|
C,
|
||||||
P: Pos<'pos>,
|
P: Pos<'pos>,
|
||||||
CS: CollectedSubstring<'source, C = C>,
|
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>,
|
I: SourceStream<'source, 'pos, C = C, P = P, CS = CS>,
|
||||||
> {
|
> {
|
||||||
_src: I,
|
_src: I,
|
||||||
|
_converter: W,
|
||||||
__phantom: PhantomData<(&'source (), &'pos (), W)>,
|
__phantom: PhantomData<(&'source (), &'pos (), W)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,7 +74,7 @@ impl<
|
|||||||
C,
|
C,
|
||||||
P: Pos<'pos>,
|
P: Pos<'pos>,
|
||||||
CS: CollectedSubstring<'source, C = C>,
|
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>,
|
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 SourceStreamWrapper<'source, 'pos, C, P, CS, W, I>
|
||||||
{
|
{
|
||||||
@ -80,11 +83,11 @@ impl<
|
|||||||
type CS = W::WCS;
|
type CS = W::WCS;
|
||||||
|
|
||||||
fn skip(&mut self, predicate: &mut impl Predicate<W::WC>) -> bool {
|
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> {
|
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::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(W::wrapSubstring(cs)),
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user