diff --git a/src/collected_substring.rs b/src/collected_substring.rs index a58f651..59eee9c 100644 --- a/src/collected_substring.rs +++ b/src/collected_substring.rs @@ -1,36 +1,33 @@ use std::slice::Iter; use std::str::Chars; -pub trait KeywordComparatorIterator<'keyword, C> { +pub trait KeywordComparatorIterator { fn consume(&mut self, c: C) -> bool; } -pub trait Keyword { +pub trait Keyword { fn startComparation<'keyword>( &'keyword self, expectedLen: usize, - ) -> Option>; + ) -> Option + use<'keyword, Self, C>>; } -pub trait CollectedSubstring<'source> { - type C; - fn compareKeyword<'keyword>(&self, kw: impl Keyword) -> bool; +pub trait CollectedSubstring { + type C: Copy; + fn compareKeyword(&self, kw: impl Keyword) -> bool; } - - -impl<'keyword> KeywordComparatorIterator<'keyword, char> for Chars<'keyword> { +impl<'keyword> KeywordComparatorIterator for Chars<'keyword> { fn consume(&mut self, e: char) -> bool { return self.next().is_some_and(|a| a == e); } } impl Keyword for &str { - fn startComparation<'keyword>( &'keyword self, expectedLen: usize, - ) -> Option> { + ) -> Option> { if self.len() != expectedLen { return Option::None; } @@ -43,7 +40,7 @@ impl Keyword for &String { fn startComparation<'keyword>( &'keyword self, expectedLen: usize, - ) -> Option> { + ) -> Option> { if self.len() != expectedLen { return Option::None; } @@ -51,17 +48,17 @@ impl Keyword for &String { return Option::Some(self.chars()); } } -impl<'keyword, C: PartialEq> KeywordComparatorIterator<'keyword, C> for Iter<'keyword, C> { +impl<'keyword, C: Copy + PartialEq> KeywordComparatorIterator for Iter<'keyword, C> { fn consume(&mut self, e: C) -> bool { return self.next().is_some_and(|a| a.eq(&e)); } } -impl Keyword for &[C] { +impl Keyword for &[C] { fn startComparation<'keyword>( &'keyword self, expectedLen: usize, - ) -> Option> { + ) -> Option> { if self.len() != expectedLen { return Option::None; } @@ -70,11 +67,11 @@ impl Keyword for &[C] { } } -impl Keyword for &[C; SZ] { +impl Keyword for &[C; SZ] { fn startComparation<'keyword>( &'keyword self, expectedLen: usize, - ) -> Option> { + ) -> Option> { if self.len() != expectedLen { return Option::None; } diff --git a/src/converter/converters.rs b/src/converter/converters.rs index 2a86677..71e9cfd 100644 --- a/src/converter/converters.rs +++ b/src/converter/converters.rs @@ -6,38 +6,28 @@ pub trait StreamConverter_Char { fn convertChar(&self, c: C) -> Self::WC; } -pub trait StreamConverter_Pos<'pos, P: Pos<'pos>> { - type WP: Pos<'pos>; +pub trait StreamConverter_Pos { + type WP: Pos; fn convertPos(&self, p: P) -> Self::WP; } -pub trait StreamConverter_Substring<'source, C: Copy, CS: CollectedSubstring<'source, C = C>>: -StreamConverter_Char +pub trait StreamConverter_Substring>: + StreamConverter_Char { - type WCS: CollectedSubstring<'source, C = Self::WC>; + type WCS: CollectedSubstring; fn convertSubstring(&self, wcs: CS) -> Self::WCS; } -pub trait StreamConverter< - 'source, - 'pos, - C: Copy, - P: Pos<'pos>, - CS: CollectedSubstring<'source, C = C>, ->: -StreamConverter_Char + StreamConverter_Pos<'pos, P> + StreamConverter_Substring<'source, C, CS> +pub trait StreamConverter>: + StreamConverter_Char + StreamConverter_Pos

+ StreamConverter_Substring { } impl< - 'source, - 'pos, C: Copy, - 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 + P: Pos, + CS: CollectedSubstring, + W: StreamConverter_Char + StreamConverter_Pos

+ StreamConverter_Substring, +> StreamConverter for W { -} \ No newline at end of file +} diff --git a/src/converter/keyword.rs b/src/converter/keyword.rs index f5b37b2..51a72ae 100644 --- a/src/converter/keyword.rs +++ b/src/converter/keyword.rs @@ -3,25 +3,23 @@ use crate::{Keyword, KeywordComparatorIterator}; use std::marker::PhantomData; struct KeywordComparatorConverter< - 'keyword, 'converter, C: Copy, W: StreamConverter_Char, - I: KeywordComparatorIterator<'keyword, W::WC>, + I: KeywordComparatorIterator, > { _orig: I, _converter: &'converter W, - __phantom: PhantomData<(&'keyword (), C)>, + __phantom: PhantomData, } impl< - 'keyword, 'converter, C: Copy, W: StreamConverter_Char, - I: KeywordComparatorIterator<'keyword, W::WC>, -> KeywordComparatorIterator<'keyword, C> - for KeywordComparatorConverter<'keyword, 'converter, C, W, I> + I: KeywordComparatorIterator, +> KeywordComparatorIterator + for KeywordComparatorConverter<'converter, C, W, I> { fn consume(&mut self, c: C) -> bool { self._orig.consume(self._converter.convertChar(c)) @@ -58,7 +56,7 @@ impl<'keyword, 'converter, C: Copy, W: StreamConverter_Char, I: Keyword( &'self_ self, expectedLen: usize, - ) -> Option> { + ) -> Option> { return self ._orig .startComparation(expectedLen) diff --git a/src/converter/noop.rs b/src/converter/noop.rs index aa89b21..aa5bc05 100644 --- a/src/converter/noop.rs +++ b/src/converter/noop.rs @@ -3,7 +3,7 @@ use crate::pos::Pos; pub trait StreamConverter_Char_Noop {} -pub trait StreamConverter_Pos_Noop<'pos, P: Pos<'pos>> {} +pub trait StreamConverter_Pos_Noop {} /* pub trait StreamConverter_Substring_Noop<'source, C: Copy, CS: CollectedSubstring<'source, C = C>>: @@ -20,7 +20,7 @@ impl> StreamConverter_Char for W { } } -impl<'pos, P: Pos<'pos>, W: StreamConverter_Pos_Noop<'pos, P>> StreamConverter_Pos<'pos, P> for W { +impl> StreamConverter_Pos

for W { type WP = P; fn convertPos(&self, p: P) -> Self::WP { diff --git a/src/converter/stream.rs b/src/converter/stream.rs index e13d6f3..0e4ef29 100644 --- a/src/converter/stream.rs +++ b/src/converter/stream.rs @@ -1,57 +1,48 @@ -use std::marker::PhantomData; -use crate::{CollectedSubstring, Predicate, SourceStream}; use crate::converter::{PredicateConverter, StreamConverter}; use crate::pos::Pos; +use crate::{CollectedSubstring, Predicate, SourceStream}; pub struct ConvertedSourceStream< - 'source, - 'pos, C: Copy, - 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>, + P: Pos, + CS: CollectedSubstring, + W: StreamConverter, + I: SourceStream, > { _src: I, _converter: W, - __phantom: PhantomData<(&'source (), &'pos (), W)>, } impl< - 'source, - 'pos, C: Copy, - 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> + P: Pos, + CS: CollectedSubstring, + W: StreamConverter, + I: SourceStream, +> ConvertedSourceStream { pub fn convert(stream: I, converter: W) -> Self { return ConvertedSourceStream { _src: stream, _converter: converter, - __phantom: PhantomData::default(), }; } } impl< - 'source, - 'pos, C: Copy, - 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 ConvertedSourceStream<'source, 'pos, C, P, CS, W, I> + P: Pos, + CS: CollectedSubstring, + W: StreamConverter, + I: SourceStream, +> SourceStream for ConvertedSourceStream { type C = W::WC; type P = W::WP; type CS = W::WCS; fn skipNext(&mut self, predicate: &mut impl Predicate) -> Option { - return self + return self ._src .skipNext(&mut PredicateConverter::wrap(predicate, &self._converter)) .map(|c| self._converter.convertChar(c)); @@ -75,4 +66,4 @@ impl< fn nextChar(&mut self) -> Option { return self._src.nextChar().map(|c| self._converter.convertChar(c)); } -} \ No newline at end of file +} diff --git a/src/default_streams/array.rs b/src/default_streams/array.rs index f4864d2..823f391 100644 --- a/src/default_streams/array.rs +++ b/src/default_streams/array.rs @@ -1,16 +1,16 @@ use crate::KeywordComparatorIterator; -use std::marker::PhantomData; -use std::slice::Iter; -use crate::{CollectedSubstring, Keyword, Predicate, SourceStream}; use crate::pos::PosCounter; +use crate::{CollectedSubstring, Keyword, Predicate, SourceStream}; +use std::slice::Iter; -pub struct ArrayCollectedSubstring<'source, C> { +pub struct ArrayCollectedSubstring<'source, C: Copy> { pub slice: &'source [C], } -impl<'source, C: Copy> CollectedSubstring<'source> for ArrayCollectedSubstring<'source, C> { +impl<'source, C: Copy> CollectedSubstring for ArrayCollectedSubstring<'source, C> { type C = C; - fn compareKeyword<'keyword>(&self, kw: impl Keyword) -> bool { + + fn compareKeyword(&self, kw: impl Keyword) -> bool { let mut kwi; match kw.startComparation(self.slice.len()) { None => return false, @@ -27,17 +27,16 @@ impl<'source, C: Copy> CollectedSubstring<'source> for ArrayCollectedSubstring<' } } -pub struct ArraySourceStream<'source, 'pos, C: Copy, PC: PosCounter<'pos, C>> { +pub struct ArraySourceStream<'source, C: Copy, PC: PosCounter> { _source: &'source [C], __iter: Iter<'source, C>, _current: C, _posRaw: usize, _posHighlevel: PC, _isEnded: bool, - __phantom: PhantomData<&'pos ()>, } -impl<'source, 'pos, C: Copy, PC: PosCounter<'pos, C>> ArraySourceStream<'source, 'pos, C, PC> { +impl<'source, C: Copy, PC: PosCounter> ArraySourceStream<'source, C, PC> { pub fn start(arr: &'source [C], pos: PC) -> Option<(Self, C)> { let mut iter = arr.iter(); let first = iter.next().copied(); @@ -51,7 +50,6 @@ impl<'source, 'pos, C: Copy, PC: PosCounter<'pos, C>> ArraySourceStream<'source, _posRaw: 0, _posHighlevel: pos, _isEnded: false, - __phantom: PhantomData::default(), }; return Some((stream, c)); } @@ -59,7 +57,7 @@ impl<'source, 'pos, C: Copy, PC: PosCounter<'pos, C>> ArraySourceStream<'source, } } -impl<'source, 'pos, C: Copy, PC: PosCounter<'pos, C>> ArraySourceStream<'source, 'pos, C, PC> { +impl<'source, 'pos, C: Copy, PC: PosCounter> ArraySourceStream<'source, C, PC> { fn _next(&mut self) -> Option { if !self._isEnded { self._posHighlevel.update(self._current); @@ -76,9 +74,7 @@ impl<'source, 'pos, C: Copy, PC: PosCounter<'pos, C>> ArraySourceStream<'source, } } -impl<'source, 'pos, C: Copy, PC: PosCounter<'pos, C>> SourceStream<'source, 'pos> - for ArraySourceStream<'source, 'pos, C, PC> -{ +impl<'source, C: Copy, PC: PosCounter> SourceStream for ArraySourceStream<'source, C, PC> { type C = C; type P = PC::P; type CS = ArrayCollectedSubstring<'source, C>; diff --git a/src/default_streams/empty.rs b/src/default_streams/empty.rs index 4b5351c..04af898 100644 --- a/src/default_streams/empty.rs +++ b/src/default_streams/empty.rs @@ -1,47 +1,24 @@ use std::marker::PhantomData; +use crate::pos::{PosCounter}; use crate::{CollectedSubstring, Predicate, SourceStream}; -use crate::pos::{Pos, PosCounter}; -pub struct EmptySourceStream< - 'source, - 'pos, - C: Copy, - P: Pos<'pos>, - CS: CollectedSubstring<'source, C=C>, - PC: PosCounter<'pos, C, P=P>, -> { +pub struct EmptySourceStream, PC: PosCounter> { _pos: PC, - __phantom: PhantomData<(&'source (), &'pos (), P, CS)>, + __phantom: PhantomData<(C, CS)> } -impl< - 'source, - 'pos, - C: Copy, - P: Pos<'pos>, - CS: CollectedSubstring<'source, C=C>, - PC: PosCounter<'pos, C, P=P>, -> EmptySourceStream<'source, 'pos, C, P, CS, PC> -{ + +impl, PC: PosCounter> EmptySourceStream { pub fn start(pos: PC) -> (Self, Option) { - let stream = EmptySourceStream { - _pos: pos, - __phantom: PhantomData::default() - }; + let stream = EmptySourceStream { _pos: pos, __phantom: PhantomData::default() }; return (stream, None); } } -impl< - 'source, - 'pos, - C: Copy, - P: Pos<'pos>, - CS: CollectedSubstring<'source, C=C>, - PC: PosCounter<'pos, C, P=P>, -> SourceStream<'source, 'pos> for EmptySourceStream<'source, 'pos, C, P, CS, PC> +impl, PC: PosCounter> SourceStream + for EmptySourceStream { type C = C; - type P = P; + type P = PC::P; type CS = CS; fn skipNext(&mut self, _: &mut impl Predicate) -> Option { diff --git a/src/default_streams/str.rs b/src/default_streams/str.rs index d5240cf..cd15ca3 100644 --- a/src/default_streams/str.rs +++ b/src/default_streams/str.rs @@ -1,18 +1,17 @@ use crate::KeywordComparatorIterator; -use std::marker::PhantomData; -use std::str::CharIndices; -use crate::{CollectedSubstring, Keyword, Predicate, SourceStream}; use crate::pos::PosCounter; +use crate::{CollectedSubstring, Keyword, Predicate, SourceStream}; +use std::str::CharIndices; pub struct StrCollectedSubstring<'source> { pub slice: &'source str, pub size: usize, } -impl<'source> CollectedSubstring<'source> for StrCollectedSubstring<'source> { +impl<'source> CollectedSubstring for StrCollectedSubstring<'source> { type C = char; - fn compareKeyword<'keyword>(&self, kw: impl Keyword) -> bool { + fn compareKeyword(&self, kw: impl Keyword) -> bool { let mut kwi; match kw.startComparation(self.size) { None => return false, @@ -29,7 +28,7 @@ impl<'source> CollectedSubstring<'source> for StrCollectedSubstring<'source> { } } -pub struct StrSourceStream<'source, 'pos, PC: PosCounter<'pos, char>> { +pub struct StrSourceStream<'source, PC: PosCounter> { _source: &'source str, __iter: CharIndices<'source>, _current: char, @@ -37,10 +36,9 @@ pub struct StrSourceStream<'source, 'pos, PC: PosCounter<'pos, char>> { _posCodePoints: usize, _posHighlevel: PC, _isEnded: bool, - __phantom: PhantomData<&'pos ()>, } -impl<'source, 'pos, PC: PosCounter<'pos, char>> StrSourceStream<'source, 'pos, PC> { +impl<'source, PC: PosCounter> StrSourceStream<'source, PC> { pub fn start(s: &'source str, pos: PC) -> Option<(Self, char)> { let mut it = s.char_indices(); let first = it.next(); @@ -55,7 +53,6 @@ impl<'source, 'pos, PC: PosCounter<'pos, char>> StrSourceStream<'source, 'pos, P _posCodePoints: 0, _posHighlevel: pos, _isEnded: false, - __phantom: PhantomData::default(), }; return Some((stream, c)); } @@ -63,7 +60,7 @@ impl<'source, 'pos, PC: PosCounter<'pos, char>> StrSourceStream<'source, 'pos, P } } -impl<'source, 'pos, PC: PosCounter<'pos, char>> StrSourceStream<'source, 'pos, PC> { +impl<'source, PC: PosCounter> StrSourceStream<'source, PC> { fn _next(&mut self) -> Option { if !self._isEnded { self._posHighlevel.update(self._current); @@ -81,9 +78,7 @@ impl<'source, 'pos, PC: PosCounter<'pos, char>> StrSourceStream<'source, 'pos, P } } -impl<'source, 'pos, PC: PosCounter<'pos, char>> SourceStream<'source, 'pos> - for StrSourceStream<'source, 'pos, PC> -{ +impl<'source, PC: PosCounter> SourceStream for StrSourceStream<'source, PC> { type C = char; type P = PC::P; type CS = StrCollectedSubstring<'source>; diff --git a/src/pos/default_counters/index.rs b/src/pos/default_counters/index.rs index 70e31c7..18656ff 100644 --- a/src/pos/default_counters/index.rs +++ b/src/pos/default_counters/index.rs @@ -10,7 +10,7 @@ impl Default for IndexPosCounter { } } -impl PosCounter<'static, C> for IndexPosCounter { +impl PosCounter for IndexPosCounter { type P = usize; fn update(&mut self, _: C) { diff --git a/src/pos/default_counters/newline.rs b/src/pos/default_counters/newline.rs index 5ebd864..9dc75ed 100644 --- a/src/pos/default_counters/newline.rs +++ b/src/pos/default_counters/newline.rs @@ -5,7 +5,7 @@ pub struct PosLineCol { pub col: usize, } -impl Pos<'static> for PosLineCol {} +impl Pos for PosLineCol {} pub struct NewLinePosCounter { row: usize, @@ -13,7 +13,7 @@ pub struct NewLinePosCounter { } impl NewLinePosCounter { - pub fn _update(&mut self, actual: C, expected: C) { + pub fn _update(&mut self, actual: C, expected: C) { if actual == expected { self.row += 1; self.col = 0; @@ -36,7 +36,7 @@ impl Default for NewLinePosCounter { } } -impl PosCounter<'static, char> for NewLinePosCounter { +impl PosCounter for NewLinePosCounter { type P = PosLineCol; fn update(&mut self, c: char) { @@ -49,7 +49,7 @@ impl PosCounter<'static, char> for NewLinePosCounter { } -impl PosCounter<'static, u8> for NewLinePosCounter { +impl PosCounter for NewLinePosCounter { type P = PosLineCol; fn update(&mut self, c: u8) { diff --git a/src/pos/default_counters/noop.rs b/src/pos/default_counters/noop.rs index 85ecdb5..cbe1c41 100644 --- a/src/pos/default_counters/noop.rs +++ b/src/pos/default_counters/noop.rs @@ -8,7 +8,7 @@ impl Default for NoopPosCounter { } } -impl PosCounter<'static, C> for NoopPosCounter { +impl PosCounter for NoopPosCounter { type P = (); fn update(&mut self, _: C) {} diff --git a/src/pos/pos.rs b/src/pos/pos.rs index 30d311e..ad8ef90 100644 --- a/src/pos/pos.rs +++ b/src/pos/pos.rs @@ -1,4 +1,4 @@ -pub trait Pos<'pos> {} +pub trait Pos {} -impl Pos<'static> for () {} -impl Pos<'static> for usize {} \ No newline at end of file +impl Pos for () {} +impl Pos for usize {} \ No newline at end of file diff --git a/src/pos/pos_counter.rs b/src/pos/pos_counter.rs index cda87ad..755f9af 100644 --- a/src/pos/pos_counter.rs +++ b/src/pos/pos_counter.rs @@ -1,10 +1,9 @@ use crate::pos::Pos; -pub trait PosCounter<'pos, C: Copy> { - type P: Pos<'pos>; +pub trait PosCounter { + type P: Pos; fn update(&mut self, c: C); fn export(&self) -> Self::P; -} - +} \ No newline at end of file diff --git a/src/stream.rs b/src/stream.rs index 57ccf3e..3fc10f8 100644 --- a/src/stream.rs +++ b/src/stream.rs @@ -5,10 +5,10 @@ pub trait Predicate { fn check(&mut self, chr: C) -> bool; } -pub trait SourceStream<'source, 'pos> { +pub trait SourceStream { type C: Copy; - type P: Pos<'pos>; - type CS: CollectedSubstring<'source, C = Self::C>; + type P: Pos; + type CS: CollectedSubstring; fn skipNext(&mut self, predicate: &mut impl Predicate) -> Option;