diff --git a/ascii/Cargo.toml b/ascii/Cargo.toml index 73d5d23..3aa5f6c 100644 --- a/ascii/Cargo.toml +++ b/ascii/Cargo.toml @@ -4,4 +4,9 @@ edition = "2024" [lib] -[dependencies] \ No newline at end of file +[dependencies] + +[dev-dependencies] +source-stream-0 = { path = ".." } +source-stream-0-default-streams-0 = { path = "../default-streams" } +source-stream-0-converter-0 = { path = "../converter" } diff --git a/ascii/src/_sandbox.rs b/ascii/src/_sandbox.rs new file mode 100644 index 0000000..d9a067d --- /dev/null +++ b/ascii/src/_sandbox.rs @@ -0,0 +1,63 @@ +use crate::{AsciiChar, AsciiCharConvertable}; +use source_stream_0::{CollectedSubstring, Pos, SourceStream}; +use source_stream_0_converter_0::{ + ConvertedSourceStream, StreamConverter, StreamConverter_Char, StreamConverter_Pos, + StreamConverter_Pos_Noop, StreamConverter_Substring, +}; +use source_stream_0_default_streams_0::SourceStreamOverIterator; +use source_stream_0_default_streams_0::iterators::{ + ArrayCollectedSubstring, ArraySourceIterator, StrSourceIterator, +}; +use source_stream_0_default_streams_0::pos::IndexPosCounter; +use std::marker::PhantomData; + +#[cfg(test)] + +struct ConverterImpl {} + +impl StreamConverter_Char for ConverterImpl { + type WC = AsciiChar; + + fn convertChar(&self, c: char) -> Self::WC { + return c.asAsciiChar(); + } +} + +impl<'pos, P: Pos<'pos>> StreamConverter_Pos_Noop<'pos, P> for ConverterImpl {} + +impl<'source, CS: CollectedSubstring<'source, C = char>> + StreamConverter_Substring<'source, char, CS> for ConverterImpl +{ + type WCS = ArrayCollectedSubstring<'source, AsciiChar>; + + fn convertSubstring(&self, wcs: CS) -> Self::WCS { + todo!() + } +} + +fn printAscii(a: Option) { + match a { + None => println!("_"), + Some(aa) => match aa { + AsciiChar::NOT_ASCII => println!("#"), + AsciiChar::ASCII(c) => println!("{}", c as char), + }, + } +} + +#[test] +fn sandbox() { + let src8 = SourceStreamOverIterator::wrap(StrSourceIterator::start( + "qwяtr", + IndexPosCounter::default(), + )); + + let cvt = ConverterImpl {}; + let mut src = ConvertedSourceStream::convert(src8, cvt); + + for _ in 0..10 { + // println!("{}", src.pos()); + printAscii(src.currentChar()); + src.nextChar(); + } +} diff --git a/ascii/src/lib.rs b/ascii/src/lib.rs index 075b769..9139b6f 100644 --- a/ascii/src/lib.rs +++ b/ascii/src/lib.rs @@ -1,5 +1,6 @@ mod char; mod converters; +mod _sandbox; pub use crate::char::AsciiChar; pub use crate::converters::AsciiCharConvertable; diff --git a/converter/src/lib.rs b/converter/src/lib.rs index 1f3bf1f..3179004 100644 --- a/converter/src/lib.rs +++ b/converter/src/lib.rs @@ -7,7 +7,7 @@ use source_stream_0::{ }; use std::marker::PhantomData; -pub trait SourceStreamConverter_Char { +pub trait StreamConverter_Char { type WC; fn convertChar(&self, c: C) -> Self::WC; } @@ -18,16 +18,27 @@ pub trait StreamConverter_Pos<'pos, P: Pos<'pos>> { } pub trait StreamConverter_Substring<'source, C, CS: CollectedSubstring<'source, C = C>>: - SourceStreamConverter_Char + StreamConverter_Char { type WCS: CollectedSubstring<'source, C = Self::WC>; fn convertSubstring(&self, 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> + StreamConverter_Char + StreamConverter_Pos<'pos, P> + StreamConverter_Substring<'source, C, CS> +{ +} + +impl< + 'source, + 'pos, + C, + P: Pos<'pos>, + CS: CollectedSubstring<'source, C = C>, + W: StreamConverter_Char + + StreamConverter_Pos<'pos, P> + + StreamConverter_Substring<'source, C, CS>, +> StreamConverter<'source, 'pos, C, P, CS> for W { } @@ -35,7 +46,7 @@ struct PredicateConverter< 'predicate, 'converter, C, - W: SourceStreamConverter_Char, + W: StreamConverter_Char, I: Predicate, > { _orig: &'predicate mut I, @@ -43,7 +54,7 @@ struct PredicateConverter< __phantom: PhantomData, } -impl<'predicate, 'converter, C, W: SourceStreamConverter_Char, I: Predicate> +impl<'predicate, 'converter, C, W: StreamConverter_Char, I: Predicate> PredicateConverter<'predicate, 'converter, C, W, I> { fn wrap(pred: &'predicate mut I, converter: &'converter W) -> Self { @@ -55,7 +66,7 @@ impl<'predicate, 'converter, C, W: SourceStreamConverter_Char, I: Predicate, I: Predicate> Predicate +impl<'predicate, 'converter, C, W: StreamConverter_Char, I: Predicate> Predicate for PredicateConverter<'predicate, 'converter, C, W, I> { fn check(&mut self, chr: C) -> bool { @@ -77,6 +88,25 @@ pub struct ConvertedSourceStream< __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>, +> ConvertedSourceStream<'source, 'pos, C, P, CS, W, I> +{ + pub fn convert(stream: I, converter: W) -> Self { + return ConvertedSourceStream { + _src: stream, + _converter: converter, + __phantom: PhantomData::default(), + }; + } +} + impl< 'source, 'pos, @@ -129,7 +159,7 @@ pub struct KeywordDeconverted< 'keyword, 'converter, C, - W: SourceStreamConverter_Char, + W: StreamConverter_Char, I: Keyword, > { _orig: &'keyword I, @@ -137,7 +167,7 @@ pub struct KeywordDeconverted< __phantom: PhantomData, } -impl<'keyword, 'converter, C, W: SourceStreamConverter_Char, I: Keyword> +impl<'keyword, 'converter, C, W: StreamConverter_Char, I: Keyword> KeywordDeconverted<'keyword, 'converter, C, W, I> { fn unwrap(kw: &'keyword I, converter: &'converter W) -> Self { @@ -149,7 +179,7 @@ impl<'keyword, 'converter, C, W: SourceStreamConverter_Char, I: Keyword, I: Keyword> Keyword +impl<'keyword, 'converter, C, W: StreamConverter_Char, I: Keyword> Keyword for KeywordDeconverted<'keyword, 'converter, C, W, I> { fn startComparation<'self_>( @@ -171,7 +201,7 @@ struct KeywordComparatorConverter< 'keyword, 'converter, C, - W: SourceStreamConverter_Char, + W: StreamConverter_Char, I: KeywordComparatorIterator<'keyword, W::WC>, > { _orig: I, @@ -183,7 +213,7 @@ impl< 'keyword, 'converter, C, - W: SourceStreamConverter_Char, + W: StreamConverter_Char, I: KeywordComparatorIterator<'keyword, W::WC>, > KeywordComparatorIterator<'keyword, C> for KeywordComparatorConverter<'keyword, 'converter, C, W, I> @@ -192,3 +222,27 @@ impl< self._orig.consume(self._converter.convertChar(c)) } } + +pub trait StreamConverter_Char_Noop {} + +pub trait StreamConverter_Pos_Noop<'pos, P: Pos<'pos>> {} + +pub trait StreamConverter_Substring_Noop<'source, C, CS: CollectedSubstring<'source, C = C>>: + StreamConverter_Char +{ +} + +impl> StreamConverter_Char for W { + type WC = C; + + fn convertChar(&self, c: C) -> Self::WC { + return c; + } +} +impl<'pos, P: Pos<'pos>, W: StreamConverter_Pos_Noop<'pos, P>> StreamConverter_Pos<'pos, P> for W { + type WP = P; + + fn convertPos(&self, p: P) -> Self::WP { + return p; + } +} diff --git a/default-streams/src/stream.rs b/default-streams/src/stream.rs index e8f5b9d..5c755d2 100644 --- a/default-streams/src/stream.rs +++ b/default-streams/src/stream.rs @@ -9,7 +9,7 @@ pub struct SourceStreamOverIterator<'source, 'pos, I: SourceIterator<'source, 'p } impl<'source, 'pos, I: SourceIterator<'source, 'pos>> SourceStreamOverIterator<'source, 'pos, I> { - fn wrap(iter: I) -> SourceStreamOverIterator<'source, 'pos, I> { + pub fn wrap(iter: I) -> SourceStreamOverIterator<'source, 'pos, I> { return SourceStreamOverIterator { _iter: iter, __phantom: PhantomData::default(),