Minor fixes
This commit is contained in:
parent
fcb530425a
commit
dfe4a58973
@ -5,3 +5,8 @@ edition = "2024"
|
||||
[lib]
|
||||
|
||||
[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
63
ascii/src/_sandbox.rs
Normal 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();
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,6 @@
|
||||
mod char;
|
||||
mod converters;
|
||||
mod _sandbox;
|
||||
|
||||
pub use crate::char::AsciiChar;
|
||||
pub use crate::converters::AsciiCharConvertable;
|
||||
|
||||
@ -7,7 +7,7 @@ use source_stream_0::{
|
||||
};
|
||||
use std::marker::PhantomData;
|
||||
|
||||
pub trait SourceStreamConverter_Char<C> {
|
||||
pub trait StreamConverter_Char<C> {
|
||||
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<C>
|
||||
StreamConverter_Char<C>
|
||||
{
|
||||
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<C>
|
||||
StreamConverter_Char<C> + 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_Substring<'source, C, CS>,
|
||||
> StreamConverter<'source, 'pos, C, P, CS> for W
|
||||
{
|
||||
}
|
||||
|
||||
@ -35,7 +46,7 @@ struct PredicateConverter<
|
||||
'predicate,
|
||||
'converter,
|
||||
C,
|
||||
W: SourceStreamConverter_Char<C>,
|
||||
W: StreamConverter_Char<C>,
|
||||
I: Predicate<W::WC>,
|
||||
> {
|
||||
_orig: &'predicate mut I,
|
||||
@ -43,7 +54,7 @@ struct PredicateConverter<
|
||||
__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>
|
||||
{
|
||||
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>
|
||||
{
|
||||
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<C>,
|
||||
W: StreamConverter_Char<C>,
|
||||
I: Keyword<W::WC>,
|
||||
> {
|
||||
_orig: &'keyword I,
|
||||
@ -137,7 +167,7 @@ pub struct KeywordDeconverted<
|
||||
__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>
|
||||
{
|
||||
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>
|
||||
{
|
||||
fn startComparation<'self_>(
|
||||
@ -171,7 +201,7 @@ struct KeywordComparatorConverter<
|
||||
'keyword,
|
||||
'converter,
|
||||
C,
|
||||
W: SourceStreamConverter_Char<C>,
|
||||
W: StreamConverter_Char<C>,
|
||||
I: KeywordComparatorIterator<'keyword, W::WC>,
|
||||
> {
|
||||
_orig: I,
|
||||
@ -183,7 +213,7 @@ impl<
|
||||
'keyword,
|
||||
'converter,
|
||||
C,
|
||||
W: SourceStreamConverter_Char<C>,
|
||||
W: StreamConverter_Char<C>,
|
||||
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<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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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(),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user