Removed lifetimes from traits
This commit is contained in:
parent
8388ea0657
commit
f6f531cf56
@ -1,36 +1,33 @@
|
|||||||
use std::slice::Iter;
|
use std::slice::Iter;
|
||||||
use std::str::Chars;
|
use std::str::Chars;
|
||||||
|
|
||||||
pub trait KeywordComparatorIterator<'keyword, C> {
|
pub trait KeywordComparatorIterator<C: Copy> {
|
||||||
fn consume(&mut self, c: C) -> bool;
|
fn consume(&mut self, c: C) -> bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Keyword<C> {
|
pub trait Keyword<C: Copy> {
|
||||||
fn startComparation<'keyword>(
|
fn startComparation<'keyword>(
|
||||||
&'keyword self,
|
&'keyword self,
|
||||||
expectedLen: usize,
|
expectedLen: usize,
|
||||||
) -> Option<impl KeywordComparatorIterator<'keyword, C>>;
|
) -> Option<impl KeywordComparatorIterator<C> + use<'keyword, Self, C>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait CollectedSubstring<'source> {
|
pub trait CollectedSubstring {
|
||||||
type C;
|
type C: Copy;
|
||||||
fn compareKeyword<'keyword>(&self, kw: impl Keyword<Self::C>) -> bool;
|
fn compareKeyword(&self, kw: impl Keyword<Self::C>) -> bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'keyword> KeywordComparatorIterator<char> for Chars<'keyword> {
|
||||||
|
|
||||||
impl<'keyword> KeywordComparatorIterator<'keyword, char> for Chars<'keyword> {
|
|
||||||
fn consume(&mut self, e: char) -> bool {
|
fn consume(&mut self, e: char) -> bool {
|
||||||
return self.next().is_some_and(|a| a == e);
|
return self.next().is_some_and(|a| a == e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Keyword<char> for &str {
|
impl Keyword<char> for &str {
|
||||||
|
|
||||||
fn startComparation<'keyword>(
|
fn startComparation<'keyword>(
|
||||||
&'keyword self,
|
&'keyword self,
|
||||||
expectedLen: usize,
|
expectedLen: usize,
|
||||||
) -> Option<impl KeywordComparatorIterator<'keyword, char>> {
|
) -> Option<impl KeywordComparatorIterator<char>> {
|
||||||
if self.len() != expectedLen {
|
if self.len() != expectedLen {
|
||||||
return Option::None;
|
return Option::None;
|
||||||
}
|
}
|
||||||
@ -43,7 +40,7 @@ impl Keyword<char> for &String {
|
|||||||
fn startComparation<'keyword>(
|
fn startComparation<'keyword>(
|
||||||
&'keyword self,
|
&'keyword self,
|
||||||
expectedLen: usize,
|
expectedLen: usize,
|
||||||
) -> Option<impl KeywordComparatorIterator<'keyword, char>> {
|
) -> Option<impl KeywordComparatorIterator<char>> {
|
||||||
if self.len() != expectedLen {
|
if self.len() != expectedLen {
|
||||||
return Option::None;
|
return Option::None;
|
||||||
}
|
}
|
||||||
@ -51,17 +48,17 @@ impl Keyword<char> for &String {
|
|||||||
return Option::Some(self.chars());
|
return Option::Some(self.chars());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl<'keyword, C: PartialEq> KeywordComparatorIterator<'keyword, C> for Iter<'keyword, C> {
|
impl<'keyword, C: Copy + PartialEq> KeywordComparatorIterator<C> for Iter<'keyword, C> {
|
||||||
fn consume(&mut self, e: C) -> bool {
|
fn consume(&mut self, e: C) -> bool {
|
||||||
return self.next().is_some_and(|a| a.eq(&e));
|
return self.next().is_some_and(|a| a.eq(&e));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<C: PartialEq> Keyword<C> for &[C] {
|
impl<C: Copy + PartialEq> Keyword<C> for &[C] {
|
||||||
fn startComparation<'keyword>(
|
fn startComparation<'keyword>(
|
||||||
&'keyword self,
|
&'keyword self,
|
||||||
expectedLen: usize,
|
expectedLen: usize,
|
||||||
) -> Option<impl KeywordComparatorIterator<'keyword, C>> {
|
) -> Option<impl KeywordComparatorIterator<C>> {
|
||||||
if self.len() != expectedLen {
|
if self.len() != expectedLen {
|
||||||
return Option::None;
|
return Option::None;
|
||||||
}
|
}
|
||||||
@ -70,11 +67,11 @@ impl<C: PartialEq> Keyword<C> for &[C] {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<C: PartialEq, const SZ: usize> Keyword<C> for &[C; SZ] {
|
impl<C: Copy + PartialEq, const SZ: usize> Keyword<C> for &[C; SZ] {
|
||||||
fn startComparation<'keyword>(
|
fn startComparation<'keyword>(
|
||||||
&'keyword self,
|
&'keyword self,
|
||||||
expectedLen: usize,
|
expectedLen: usize,
|
||||||
) -> Option<impl KeywordComparatorIterator<'keyword, C>> {
|
) -> Option<impl KeywordComparatorIterator<C>> {
|
||||||
if self.len() != expectedLen {
|
if self.len() != expectedLen {
|
||||||
return Option::None;
|
return Option::None;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,38 +6,28 @@ pub trait StreamConverter_Char<C: Copy> {
|
|||||||
fn convertChar(&self, c: C) -> Self::WC;
|
fn convertChar(&self, c: C) -> Self::WC;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait StreamConverter_Pos<'pos, P: Pos<'pos>> {
|
pub trait StreamConverter_Pos<P: Pos> {
|
||||||
type WP: Pos<'pos>;
|
type WP: Pos;
|
||||||
fn convertPos(&self, p: P) -> Self::WP;
|
fn convertPos(&self, p: P) -> Self::WP;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait StreamConverter_Substring<'source, C: Copy, CS: CollectedSubstring<'source, C = C>>:
|
pub trait StreamConverter_Substring<C: Copy, CS: CollectedSubstring<C = C>>:
|
||||||
StreamConverter_Char<C>
|
StreamConverter_Char<C>
|
||||||
{
|
{
|
||||||
type WCS: CollectedSubstring<'source, C = Self::WC>;
|
type WCS: CollectedSubstring<C = Self::WC>;
|
||||||
fn convertSubstring(&self, wcs: CS) -> Self::WCS;
|
fn convertSubstring(&self, wcs: CS) -> Self::WCS;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait StreamConverter<
|
pub trait StreamConverter<C: Copy, P: Pos, CS: CollectedSubstring<C = C>>:
|
||||||
'source,
|
StreamConverter_Char<C> + StreamConverter_Pos<P> + StreamConverter_Substring<C, CS>
|
||||||
'pos,
|
|
||||||
C: Copy,
|
|
||||||
P: Pos<'pos>,
|
|
||||||
CS: CollectedSubstring<'source, C = C>,
|
|
||||||
>:
|
|
||||||
StreamConverter_Char<C> + StreamConverter_Pos<'pos, P> + StreamConverter_Substring<'source, C, CS>
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<
|
impl<
|
||||||
'source,
|
|
||||||
'pos,
|
|
||||||
C: Copy,
|
C: Copy,
|
||||||
P: Pos<'pos>,
|
P: Pos,
|
||||||
CS: CollectedSubstring<'source, C = C>,
|
CS: CollectedSubstring<C = C>,
|
||||||
W: StreamConverter_Char<C>
|
W: StreamConverter_Char<C> + StreamConverter_Pos<P> + StreamConverter_Substring<C, CS>,
|
||||||
+ StreamConverter_Pos<'pos, P>
|
> StreamConverter<C, P, CS> for W
|
||||||
+ StreamConverter_Substring<'source, C, CS>,
|
|
||||||
> StreamConverter<'source, 'pos, C, P, CS> for W
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -3,25 +3,23 @@ use crate::{Keyword, KeywordComparatorIterator};
|
|||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
struct KeywordComparatorConverter<
|
struct KeywordComparatorConverter<
|
||||||
'keyword,
|
|
||||||
'converter,
|
'converter,
|
||||||
C: Copy,
|
C: Copy,
|
||||||
W: StreamConverter_Char<C>,
|
W: StreamConverter_Char<C>,
|
||||||
I: KeywordComparatorIterator<'keyword, W::WC>,
|
I: KeywordComparatorIterator<W::WC>,
|
||||||
> {
|
> {
|
||||||
_orig: I,
|
_orig: I,
|
||||||
_converter: &'converter W,
|
_converter: &'converter W,
|
||||||
__phantom: PhantomData<(&'keyword (), C)>,
|
__phantom: PhantomData<C>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<
|
impl<
|
||||||
'keyword,
|
|
||||||
'converter,
|
'converter,
|
||||||
C: Copy,
|
C: Copy,
|
||||||
W: StreamConverter_Char<C>,
|
W: StreamConverter_Char<C>,
|
||||||
I: KeywordComparatorIterator<'keyword, W::WC>,
|
I: KeywordComparatorIterator<W::WC>,
|
||||||
> KeywordComparatorIterator<'keyword, C>
|
> KeywordComparatorIterator<C>
|
||||||
for KeywordComparatorConverter<'keyword, 'converter, C, W, I>
|
for KeywordComparatorConverter<'converter, C, W, I>
|
||||||
{
|
{
|
||||||
fn consume(&mut self, c: C) -> bool {
|
fn consume(&mut self, c: C) -> bool {
|
||||||
self._orig.consume(self._converter.convertChar(c))
|
self._orig.consume(self._converter.convertChar(c))
|
||||||
@ -58,7 +56,7 @@ impl<'keyword, 'converter, C: Copy, W: StreamConverter_Char<C>, I: Keyword<W::WC
|
|||||||
fn startComparation<'self_>(
|
fn startComparation<'self_>(
|
||||||
&'self_ self,
|
&'self_ self,
|
||||||
expectedLen: usize,
|
expectedLen: usize,
|
||||||
) -> Option<impl KeywordComparatorIterator<'self_, C>> {
|
) -> Option<impl KeywordComparatorIterator<C>> {
|
||||||
return self
|
return self
|
||||||
._orig
|
._orig
|
||||||
.startComparation(expectedLen)
|
.startComparation(expectedLen)
|
||||||
|
|||||||
@ -3,7 +3,7 @@ use crate::pos::Pos;
|
|||||||
|
|
||||||
pub trait StreamConverter_Char_Noop<C: Copy> {}
|
pub trait StreamConverter_Char_Noop<C: Copy> {}
|
||||||
|
|
||||||
pub trait StreamConverter_Pos_Noop<'pos, P: Pos<'pos>> {}
|
pub trait StreamConverter_Pos_Noop<P: Pos> {}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
pub trait StreamConverter_Substring_Noop<'source, C: Copy, CS: CollectedSubstring<'source, C = C>>:
|
pub trait StreamConverter_Substring_Noop<'source, C: Copy, CS: CollectedSubstring<'source, C = C>>:
|
||||||
@ -20,7 +20,7 @@ impl<C: Copy, W: StreamConverter_Char_Noop<C>> StreamConverter_Char<C> for W {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'pos, P: Pos<'pos>, W: StreamConverter_Pos_Noop<'pos, P>> StreamConverter_Pos<'pos, P> for W {
|
impl<P: Pos, W: StreamConverter_Pos_Noop<P>> StreamConverter_Pos<P> for W {
|
||||||
type WP = P;
|
type WP = P;
|
||||||
|
|
||||||
fn convertPos(&self, p: P) -> Self::WP {
|
fn convertPos(&self, p: P) -> Self::WP {
|
||||||
|
|||||||
@ -1,50 +1,41 @@
|
|||||||
use std::marker::PhantomData;
|
|
||||||
use crate::{CollectedSubstring, Predicate, SourceStream};
|
|
||||||
use crate::converter::{PredicateConverter, StreamConverter};
|
use crate::converter::{PredicateConverter, StreamConverter};
|
||||||
use crate::pos::Pos;
|
use crate::pos::Pos;
|
||||||
|
use crate::{CollectedSubstring, Predicate, SourceStream};
|
||||||
|
|
||||||
pub struct ConvertedSourceStream<
|
pub struct ConvertedSourceStream<
|
||||||
'source,
|
|
||||||
'pos,
|
|
||||||
C: Copy,
|
C: Copy,
|
||||||
P: Pos<'pos>,
|
P: Pos,
|
||||||
CS: CollectedSubstring<'source, C = C>,
|
CS: CollectedSubstring<C = C>,
|
||||||
W: StreamConverter<'source, 'pos, C, P, CS>,
|
W: StreamConverter<C, P, CS>,
|
||||||
I: SourceStream<'source, 'pos, C = C, P = P, CS = CS>,
|
I: SourceStream<C = C, P = P, CS = CS>,
|
||||||
> {
|
> {
|
||||||
_src: I,
|
_src: I,
|
||||||
_converter: W,
|
_converter: W,
|
||||||
__phantom: PhantomData<(&'source (), &'pos (), W)>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<
|
impl<
|
||||||
'source,
|
|
||||||
'pos,
|
|
||||||
C: Copy,
|
C: Copy,
|
||||||
P: Pos<'pos>,
|
P: Pos,
|
||||||
CS: CollectedSubstring<'source, C = C>,
|
CS: CollectedSubstring<C = C>,
|
||||||
W: StreamConverter<'source, 'pos, C, P, CS>,
|
W: StreamConverter<C, P, CS>,
|
||||||
I: SourceStream<'source, 'pos, C = C, P = P, CS = CS>,
|
I: SourceStream<C = C, P = P, CS = CS>,
|
||||||
> ConvertedSourceStream<'source, 'pos, C, P, CS, W, I>
|
> ConvertedSourceStream<C, P, CS, W, I>
|
||||||
{
|
{
|
||||||
pub fn convert(stream: I, converter: W) -> Self {
|
pub fn convert(stream: I, converter: W) -> Self {
|
||||||
return ConvertedSourceStream {
|
return ConvertedSourceStream {
|
||||||
_src: stream,
|
_src: stream,
|
||||||
_converter: converter,
|
_converter: converter,
|
||||||
__phantom: PhantomData::default(),
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<
|
impl<
|
||||||
'source,
|
|
||||||
'pos,
|
|
||||||
C: Copy,
|
C: Copy,
|
||||||
P: Pos<'pos>,
|
P: Pos,
|
||||||
CS: CollectedSubstring<'source, C = C>,
|
CS: CollectedSubstring<C = C>,
|
||||||
W: StreamConverter<'source, 'pos, C, P, CS>,
|
W: StreamConverter<C, P, CS>,
|
||||||
I: SourceStream<'source, 'pos, C = C, P = P, CS = CS>,
|
I: SourceStream<C = C, P = P, CS = CS>,
|
||||||
> SourceStream<'source, 'pos> for ConvertedSourceStream<'source, 'pos, C, P, CS, W, I>
|
> SourceStream for ConvertedSourceStream<C, P, CS, W, I>
|
||||||
{
|
{
|
||||||
type C = W::WC;
|
type C = W::WC;
|
||||||
type P = W::WP;
|
type P = W::WP;
|
||||||
|
|||||||
@ -1,16 +1,16 @@
|
|||||||
use crate::KeywordComparatorIterator;
|
use crate::KeywordComparatorIterator;
|
||||||
use std::marker::PhantomData;
|
|
||||||
use std::slice::Iter;
|
|
||||||
use crate::{CollectedSubstring, Keyword, Predicate, SourceStream};
|
|
||||||
use crate::pos::PosCounter;
|
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],
|
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;
|
type C = C;
|
||||||
fn compareKeyword<'keyword>(&self, kw: impl Keyword<C>) -> bool {
|
|
||||||
|
fn compareKeyword(&self, kw: impl Keyword<C>) -> bool {
|
||||||
let mut kwi;
|
let mut kwi;
|
||||||
match kw.startComparation(self.slice.len()) {
|
match kw.startComparation(self.slice.len()) {
|
||||||
None => return false,
|
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<C>> {
|
||||||
_source: &'source [C],
|
_source: &'source [C],
|
||||||
__iter: Iter<'source, C>,
|
__iter: Iter<'source, C>,
|
||||||
_current: C,
|
_current: C,
|
||||||
_posRaw: usize,
|
_posRaw: usize,
|
||||||
_posHighlevel: PC,
|
_posHighlevel: PC,
|
||||||
_isEnded: bool,
|
_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<C>> ArraySourceStream<'source, C, PC> {
|
||||||
pub fn start(arr: &'source [C], pos: PC) -> Option<(Self, C)> {
|
pub fn start(arr: &'source [C], pos: PC) -> Option<(Self, C)> {
|
||||||
let mut iter = arr.iter();
|
let mut iter = arr.iter();
|
||||||
let first = iter.next().copied();
|
let first = iter.next().copied();
|
||||||
@ -51,7 +50,6 @@ impl<'source, 'pos, C: Copy, PC: PosCounter<'pos, C>> ArraySourceStream<'source,
|
|||||||
_posRaw: 0,
|
_posRaw: 0,
|
||||||
_posHighlevel: pos,
|
_posHighlevel: pos,
|
||||||
_isEnded: false,
|
_isEnded: false,
|
||||||
__phantom: PhantomData::default(),
|
|
||||||
};
|
};
|
||||||
return Some((stream, c));
|
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<C>> ArraySourceStream<'source, C, PC> {
|
||||||
fn _next(&mut self) -> Option<C> {
|
fn _next(&mut self) -> Option<C> {
|
||||||
if !self._isEnded {
|
if !self._isEnded {
|
||||||
self._posHighlevel.update(self._current);
|
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>
|
impl<'source, C: Copy, PC: PosCounter<C>> SourceStream for ArraySourceStream<'source, C, PC> {
|
||||||
for ArraySourceStream<'source, 'pos, C, PC>
|
|
||||||
{
|
|
||||||
type C = C;
|
type C = C;
|
||||||
type P = PC::P;
|
type P = PC::P;
|
||||||
type CS = ArrayCollectedSubstring<'source, C>;
|
type CS = ArrayCollectedSubstring<'source, C>;
|
||||||
|
|||||||
@ -1,47 +1,24 @@
|
|||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
use crate::pos::{PosCounter};
|
||||||
use crate::{CollectedSubstring, Predicate, SourceStream};
|
use crate::{CollectedSubstring, Predicate, SourceStream};
|
||||||
use crate::pos::{Pos, PosCounter};
|
|
||||||
|
|
||||||
pub struct EmptySourceStream<
|
pub struct EmptySourceStream<C: Copy, CS: CollectedSubstring<C = C>, PC: PosCounter<C>> {
|
||||||
'source,
|
|
||||||
'pos,
|
|
||||||
C: Copy,
|
|
||||||
P: Pos<'pos>,
|
|
||||||
CS: CollectedSubstring<'source, C=C>,
|
|
||||||
PC: PosCounter<'pos, C, P=P>,
|
|
||||||
> {
|
|
||||||
_pos: PC,
|
_pos: PC,
|
||||||
__phantom: PhantomData<(&'source (), &'pos (), P, CS)>,
|
__phantom: PhantomData<(C, CS)>
|
||||||
}
|
}
|
||||||
impl<
|
|
||||||
'source,
|
impl<C: Copy, CS: CollectedSubstring<C = C>, PC: PosCounter<C>> EmptySourceStream<C, CS, PC> {
|
||||||
'pos,
|
|
||||||
C: Copy,
|
|
||||||
P: Pos<'pos>,
|
|
||||||
CS: CollectedSubstring<'source, C=C>,
|
|
||||||
PC: PosCounter<'pos, C, P=P>,
|
|
||||||
> EmptySourceStream<'source, 'pos, C, P, CS, PC>
|
|
||||||
{
|
|
||||||
pub fn start(pos: PC) -> (Self, Option<C>) {
|
pub fn start(pos: PC) -> (Self, Option<C>) {
|
||||||
let stream = EmptySourceStream {
|
let stream = EmptySourceStream { _pos: pos, __phantom: PhantomData::default() };
|
||||||
_pos: pos,
|
|
||||||
__phantom: PhantomData::default()
|
|
||||||
};
|
|
||||||
return (stream, None);
|
return (stream, None);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<
|
impl<C: Copy, CS: CollectedSubstring<C = C>, PC: PosCounter<C>> SourceStream
|
||||||
'source,
|
for EmptySourceStream<C, CS, PC>
|
||||||
'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>
|
|
||||||
{
|
{
|
||||||
type C = C;
|
type C = C;
|
||||||
type P = P;
|
type P = PC::P;
|
||||||
type CS = CS;
|
type CS = CS;
|
||||||
|
|
||||||
fn skipNext(&mut self, _: &mut impl Predicate<Self::C>) -> Option<Self::C> {
|
fn skipNext(&mut self, _: &mut impl Predicate<Self::C>) -> Option<Self::C> {
|
||||||
|
|||||||
@ -1,18 +1,17 @@
|
|||||||
use crate::KeywordComparatorIterator;
|
use crate::KeywordComparatorIterator;
|
||||||
use std::marker::PhantomData;
|
|
||||||
use std::str::CharIndices;
|
|
||||||
use crate::{CollectedSubstring, Keyword, Predicate, SourceStream};
|
|
||||||
use crate::pos::PosCounter;
|
use crate::pos::PosCounter;
|
||||||
|
use crate::{CollectedSubstring, Keyword, Predicate, SourceStream};
|
||||||
|
use std::str::CharIndices;
|
||||||
|
|
||||||
pub struct StrCollectedSubstring<'source> {
|
pub struct StrCollectedSubstring<'source> {
|
||||||
pub slice: &'source str,
|
pub slice: &'source str,
|
||||||
pub size: usize,
|
pub size: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'source> CollectedSubstring<'source> for StrCollectedSubstring<'source> {
|
impl<'source> CollectedSubstring for StrCollectedSubstring<'source> {
|
||||||
type C = char;
|
type C = char;
|
||||||
|
|
||||||
fn compareKeyword<'keyword>(&self, kw: impl Keyword<char>) -> bool {
|
fn compareKeyword(&self, kw: impl Keyword<char>) -> bool {
|
||||||
let mut kwi;
|
let mut kwi;
|
||||||
match kw.startComparation(self.size) {
|
match kw.startComparation(self.size) {
|
||||||
None => return false,
|
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<char>> {
|
||||||
_source: &'source str,
|
_source: &'source str,
|
||||||
__iter: CharIndices<'source>,
|
__iter: CharIndices<'source>,
|
||||||
_current: char,
|
_current: char,
|
||||||
@ -37,10 +36,9 @@ pub struct StrSourceStream<'source, 'pos, PC: PosCounter<'pos, char>> {
|
|||||||
_posCodePoints: usize,
|
_posCodePoints: usize,
|
||||||
_posHighlevel: PC,
|
_posHighlevel: PC,
|
||||||
_isEnded: bool,
|
_isEnded: bool,
|
||||||
__phantom: PhantomData<&'pos ()>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'source, 'pos, PC: PosCounter<'pos, char>> StrSourceStream<'source, 'pos, PC> {
|
impl<'source, PC: PosCounter<char>> StrSourceStream<'source, PC> {
|
||||||
pub fn start(s: &'source str, pos: PC) -> Option<(Self, char)> {
|
pub fn start(s: &'source str, pos: PC) -> Option<(Self, char)> {
|
||||||
let mut it = s.char_indices();
|
let mut it = s.char_indices();
|
||||||
let first = it.next();
|
let first = it.next();
|
||||||
@ -55,7 +53,6 @@ impl<'source, 'pos, PC: PosCounter<'pos, char>> StrSourceStream<'source, 'pos, P
|
|||||||
_posCodePoints: 0,
|
_posCodePoints: 0,
|
||||||
_posHighlevel: pos,
|
_posHighlevel: pos,
|
||||||
_isEnded: false,
|
_isEnded: false,
|
||||||
__phantom: PhantomData::default(),
|
|
||||||
};
|
};
|
||||||
return Some((stream, c));
|
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<char>> StrSourceStream<'source, PC> {
|
||||||
fn _next(&mut self) -> Option<char> {
|
fn _next(&mut self) -> Option<char> {
|
||||||
if !self._isEnded {
|
if !self._isEnded {
|
||||||
self._posHighlevel.update(self._current);
|
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>
|
impl<'source, PC: PosCounter<char>> SourceStream for StrSourceStream<'source, PC> {
|
||||||
for StrSourceStream<'source, 'pos, PC>
|
|
||||||
{
|
|
||||||
type C = char;
|
type C = char;
|
||||||
type P = PC::P;
|
type P = PC::P;
|
||||||
type CS = StrCollectedSubstring<'source>;
|
type CS = StrCollectedSubstring<'source>;
|
||||||
|
|||||||
@ -10,7 +10,7 @@ impl Default for IndexPosCounter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<C: Copy> PosCounter<'static, C> for IndexPosCounter {
|
impl<C: Copy> PosCounter<C> for IndexPosCounter {
|
||||||
type P = usize;
|
type P = usize;
|
||||||
|
|
||||||
fn update(&mut self, _: C) {
|
fn update(&mut self, _: C) {
|
||||||
|
|||||||
@ -5,7 +5,7 @@ pub struct PosLineCol {
|
|||||||
pub col: usize,
|
pub col: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Pos<'static> for PosLineCol {}
|
impl Pos for PosLineCol {}
|
||||||
|
|
||||||
pub struct NewLinePosCounter {
|
pub struct NewLinePosCounter {
|
||||||
row: usize,
|
row: usize,
|
||||||
@ -13,7 +13,7 @@ pub struct NewLinePosCounter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl NewLinePosCounter {
|
impl NewLinePosCounter {
|
||||||
pub fn _update<C: PartialEq>(&mut self, actual: C, expected: C) {
|
pub fn _update<C: Copy + PartialEq>(&mut self, actual: C, expected: C) {
|
||||||
if actual == expected {
|
if actual == expected {
|
||||||
self.row += 1;
|
self.row += 1;
|
||||||
self.col = 0;
|
self.col = 0;
|
||||||
@ -36,7 +36,7 @@ impl Default for NewLinePosCounter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PosCounter<'static, char> for NewLinePosCounter {
|
impl PosCounter<char> for NewLinePosCounter {
|
||||||
type P = PosLineCol;
|
type P = PosLineCol;
|
||||||
|
|
||||||
fn update(&mut self, c: char) {
|
fn update(&mut self, c: char) {
|
||||||
@ -49,7 +49,7 @@ impl PosCounter<'static, char> for NewLinePosCounter {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PosCounter<'static, u8> for NewLinePosCounter {
|
impl PosCounter<u8> for NewLinePosCounter {
|
||||||
type P = PosLineCol;
|
type P = PosLineCol;
|
||||||
|
|
||||||
fn update(&mut self, c: u8) {
|
fn update(&mut self, c: u8) {
|
||||||
|
|||||||
@ -8,7 +8,7 @@ impl Default for NoopPosCounter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<C: Copy> PosCounter<'static, C> for NoopPosCounter {
|
impl<C: Copy> PosCounter<C> for NoopPosCounter {
|
||||||
type P = ();
|
type P = ();
|
||||||
|
|
||||||
fn update(&mut self, _: C) {}
|
fn update(&mut self, _: C) {}
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
pub trait Pos<'pos> {}
|
pub trait Pos {}
|
||||||
|
|
||||||
impl Pos<'static> for () {}
|
impl Pos for () {}
|
||||||
impl Pos<'static> for usize {}
|
impl Pos for usize {}
|
||||||
@ -1,10 +1,9 @@
|
|||||||
use crate::pos::Pos;
|
use crate::pos::Pos;
|
||||||
|
|
||||||
pub trait PosCounter<'pos, C: Copy> {
|
pub trait PosCounter<C: Copy> {
|
||||||
type P: Pos<'pos>;
|
type P: Pos;
|
||||||
|
|
||||||
fn update(&mut self, c: C);
|
fn update(&mut self, c: C);
|
||||||
|
|
||||||
fn export(&self) -> Self::P;
|
fn export(&self) -> Self::P;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -5,10 +5,10 @@ pub trait Predicate<C: Copy> {
|
|||||||
fn check(&mut self, chr: C) -> bool;
|
fn check(&mut self, chr: C) -> bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait SourceStream<'source, 'pos> {
|
pub trait SourceStream {
|
||||||
type C: Copy;
|
type C: Copy;
|
||||||
type P: Pos<'pos>;
|
type P: Pos;
|
||||||
type CS: CollectedSubstring<'source, C = Self::C>;
|
type CS: CollectedSubstring<C = Self::C>;
|
||||||
|
|
||||||
fn skipNext(&mut self, predicate: &mut impl Predicate<Self::C>) -> Option<Self::C>;
|
fn skipNext(&mut self, predicate: &mut impl Predicate<Self::C>) -> Option<Self::C>;
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user