Minor fixes

This commit is contained in:
Andrew Golovashevich 2025-11-18 16:36:48 +03:00
parent fcb530425a
commit dfe4a58973
5 changed files with 138 additions and 15 deletions

View File

@ -5,3 +5,8 @@ edition = "2024"
[lib] [lib]
[dependencies] [dependencies]
[dev-dependencies]
source-stream-0 = { path = ".." }
source-stream-0-default-streams-0 = { path = "../default-streams" }
source-stream-0-converter-0 = { path = "../converter" }

63
ascii/src/_sandbox.rs Normal file
View File

@ -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<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<AsciiChar>) {
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();
}
}

View File

@ -1,5 +1,6 @@
mod char; mod char;
mod converters; mod converters;
mod _sandbox;
pub use crate::char::AsciiChar; pub use crate::char::AsciiChar;
pub use crate::converters::AsciiCharConvertable; pub use crate::converters::AsciiCharConvertable;

View File

@ -7,7 +7,7 @@ use source_stream_0::{
}; };
use std::marker::PhantomData; use std::marker::PhantomData;
pub trait SourceStreamConverter_Char<C> { pub trait StreamConverter_Char<C> {
type WC; type WC;
fn convertChar(&self, c: C) -> Self::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>>: pub trait StreamConverter_Substring<'source, C, CS: CollectedSubstring<'source, C = C>>:
SourceStreamConverter_Char<C> StreamConverter_Char<C>
{ {
type WCS: CollectedSubstring<'source, C = Self::WC>; type WCS: CollectedSubstring<'source, C = Self::WC>;
fn convertSubstring(&self, 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>>:
SourceStreamConverter_Char<C> StreamConverter_Char<C> + StreamConverter_Pos<'pos, P> + StreamConverter_Substring<'source, C, CS>
+ StreamConverter_Pos<'pos, P> {
+ StreamConverter_Substring<'source, C, CS> }
impl<
'source,
'pos,
C,
P: Pos<'pos>,
CS: CollectedSubstring<'source, C = C>,
W: StreamConverter_Char<C>
+ StreamConverter_Pos<'pos, P>
+ StreamConverter_Substring<'source, C, CS>,
> StreamConverter<'source, 'pos, C, P, CS> for W
{ {
} }
@ -35,7 +46,7 @@ struct PredicateConverter<
'predicate, 'predicate,
'converter, 'converter,
C, C,
W: SourceStreamConverter_Char<C>, W: StreamConverter_Char<C>,
I: Predicate<W::WC>, I: Predicate<W::WC>,
> { > {
_orig: &'predicate mut I, _orig: &'predicate mut I,
@ -43,7 +54,7 @@ struct PredicateConverter<
__phantom: PhantomData<C>, __phantom: PhantomData<C>,
} }
impl<'predicate, 'converter, C, W: SourceStreamConverter_Char<C>, I: Predicate<W::WC>> impl<'predicate, 'converter, C, W: StreamConverter_Char<C>, I: Predicate<W::WC>>
PredicateConverter<'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 {
@ -55,7 +66,7 @@ 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: StreamConverter_Char<C>, I: Predicate<W::WC>> Predicate<C>
for PredicateConverter<'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 {
@ -77,6 +88,25 @@ pub struct ConvertedSourceStream<
__phantom: PhantomData<(&'source (), &'pos (), 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>,
> 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< impl<
'source, 'source,
'pos, 'pos,
@ -129,7 +159,7 @@ pub struct KeywordDeconverted<
'keyword, 'keyword,
'converter, 'converter,
C, C,
W: SourceStreamConverter_Char<C>, W: StreamConverter_Char<C>,
I: Keyword<W::WC>, I: Keyword<W::WC>,
> { > {
_orig: &'keyword I, _orig: &'keyword I,
@ -137,7 +167,7 @@ pub struct KeywordDeconverted<
__phantom: PhantomData<C>, __phantom: PhantomData<C>,
} }
impl<'keyword, 'converter, C, W: SourceStreamConverter_Char<C>, I: Keyword<W::WC>> impl<'keyword, 'converter, C, W: StreamConverter_Char<C>, I: Keyword<W::WC>>
KeywordDeconverted<'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 {
@ -149,7 +179,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: StreamConverter_Char<C>, I: Keyword<W::WC>> Keyword<C>
for KeywordDeconverted<'keyword, 'converter, C, W, I> for KeywordDeconverted<'keyword, 'converter, C, W, I>
{ {
fn startComparation<'self_>( fn startComparation<'self_>(
@ -171,7 +201,7 @@ struct KeywordComparatorConverter<
'keyword, 'keyword,
'converter, 'converter,
C, C,
W: SourceStreamConverter_Char<C>, W: StreamConverter_Char<C>,
I: KeywordComparatorIterator<'keyword, W::WC>, I: KeywordComparatorIterator<'keyword, W::WC>,
> { > {
_orig: I, _orig: I,
@ -183,7 +213,7 @@ impl<
'keyword, 'keyword,
'converter, 'converter,
C, C,
W: SourceStreamConverter_Char<C>, W: StreamConverter_Char<C>,
I: KeywordComparatorIterator<'keyword, W::WC>, I: KeywordComparatorIterator<'keyword, W::WC>,
> KeywordComparatorIterator<'keyword, C> > KeywordComparatorIterator<'keyword, C>
for KeywordComparatorConverter<'keyword, 'converter, C, W, I> for KeywordComparatorConverter<'keyword, 'converter, C, W, I>
@ -192,3 +222,27 @@ impl<
self._orig.consume(self._converter.convertChar(c)) self._orig.consume(self._converter.convertChar(c))
} }
} }
pub trait StreamConverter_Char_Noop<C> {}
pub trait StreamConverter_Pos_Noop<'pos, P: Pos<'pos>> {}
pub trait StreamConverter_Substring_Noop<'source, C, CS: CollectedSubstring<'source, C = C>>:
StreamConverter_Char<C>
{
}
impl<C, W: StreamConverter_Char_Noop<C>> StreamConverter_Char<C> 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;
}
}

View File

@ -9,7 +9,7 @@ pub struct SourceStreamOverIterator<'source, 'pos, I: SourceIterator<'source, 'p
} }
impl<'source, 'pos, I: SourceIterator<'source, 'pos>> SourceStreamOverIterator<'source, 'pos, I> { 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 { return SourceStreamOverIterator {
_iter: iter, _iter: iter,
__phantom: PhantomData::default(), __phantom: PhantomData::default(),