#![allow(non_camel_case_types)] #![allow(non_snake_case)] use source_stream_0::{ CollectResult, CollectedSubstring, Keyword, KeywordComparatorIterator, Pos, Predicate, SourceStream, }; use std::marker::PhantomData; pub trait SourceStreamConverter_Char { type WC; fn wrapChar(c: C) -> Self::WC; } pub trait StreamConverter_Pos<'pos, P: Pos<'pos>> { type WP: Pos<'pos>; fn wrapPos(p: P) -> Self::WP; } pub trait StreamConverter_Substring<'source, C, CS: CollectedSubstring<'source, C = C>>: SourceStreamConverter_Char { type WCS: CollectedSubstring<'source, C = Self::WC>; fn wrapSubstring(wcs: CS) -> Self::WCS; } pub trait StreamConverter<'source, 'pos, C, P: Pos<'pos>, CS: CollectedSubstring<'source, C = C>>: SourceStreamConverter_Char + StreamConverter_Pos<'pos, P> + StreamConverter_Substring<'source, C, CS> { } struct PredicateWrapper< 'predicate, 'converter, C, W: SourceStreamConverter_Char, I: Predicate, > { _orig: &'predicate mut I, _converter: &'converter W, __phantom: PhantomData, } impl<'predicate, 'converter, C, W: SourceStreamConverter_Char, I: Predicate> PredicateWrapper<'predicate, 'converter, C, W, I> { fn wrap(pred: &'predicate mut I, converter: &'converter W) -> Self { return PredicateWrapper { _orig: pred, _converter: converter, __phantom: PhantomData::default(), }; } } impl<'predicate, 'converter, C, W: SourceStreamConverter_Char, I: Predicate> Predicate for PredicateWrapper<'predicate, 'converter, C, W, I> { 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: 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)>, } impl< 'source, 'pos, C, P: Pos<'pos>, 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> { type C = W::WC; type P = W::WP; type CS = W::WCS; fn skip(&mut self, predicate: &mut impl Predicate) -> bool { self._src .skip(&mut PredicateWrapper::wrap(predicate, &self._converter)) } fn collect(&mut self, predicate: &mut impl Predicate) -> CollectResult { 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)), } } fn pos(&self) -> W::WP { return W::wrapPos(self._src.pos()); } fn currentChar(&self) -> Option { return self._src.currentChar().map(W::wrapChar); } fn nextChar(&mut self) -> Option { return self._src.nextChar().map(W::wrapChar); } } pub struct KeywordUnwrapper< 'keyword, 'converter, C, W: SourceStreamConverter_Char, I: Keyword, > { _orig: &'keyword I, _converter: &'converter W, __phantom: PhantomData, } impl<'keyword, 'converter, C, W: SourceStreamConverter_Char, I: Keyword> KeywordUnwrapper<'keyword, 'converter, C, W, I> { fn unwrap(kw: &'keyword I, converter: &'converter W) -> Self { return KeywordUnwrapper { _orig: kw, _converter: converter, __phantom: PhantomData::default(), }; } } impl<'keyword, 'converter, C, W: SourceStreamConverter_Char, I: Keyword> Keyword for KeywordUnwrapper<'keyword, 'converter, C, W, I> { fn startComparation<'self_>( &'self_ self, expectedLen: usize, ) -> Option> { return self ._orig .startComparation(expectedLen) .map(|it| KeywordComparatorWrapper { _orig: it, _converter: self._converter, __phantom: PhantomData::default(), }); } } struct KeywordComparatorWrapper< 'keyword, 'converter, C, W: SourceStreamConverter_Char, I: KeywordComparatorIterator<'keyword, W::WC>, > { _orig: I, _converter: &'converter W, __phantom: PhantomData<(&'keyword(), C)>, } impl< 'keyword, 'converter, C, W: SourceStreamConverter_Char, I: KeywordComparatorIterator<'keyword, W::WC>, > KeywordComparatorIterator<'keyword, C> for KeywordComparatorWrapper<'keyword, 'converter, C, W, I> { fn consume(&mut self, c: C) -> bool { todo!() } }