Char type in keyword moved from associated type to generic and removed lifetime parameter
This commit is contained in:
parent
267e8fb82d
commit
e1a5aa8562
@ -10,7 +10,7 @@ pub struct ArrayCollectedSubstring<'source, C> {
|
|||||||
|
|
||||||
impl<'source, C: Copy> CollectedSubstring<'source> for ArrayCollectedSubstring<'source, C> {
|
impl<'source, C: Copy> CollectedSubstring<'source> for ArrayCollectedSubstring<'source, C> {
|
||||||
type C = C;
|
type C = C;
|
||||||
fn compareKeyword<'keyword>(&self, kw: impl Keyword<'keyword, C = C>) -> bool {
|
fn compareKeyword<'keyword>(&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,
|
||||||
|
|||||||
@ -12,7 +12,7 @@ pub struct StrCollectedSubstring<'source> {
|
|||||||
impl<'source> CollectedSubstring<'source> for StrCollectedSubstring<'source> {
|
impl<'source> CollectedSubstring<'source> for StrCollectedSubstring<'source> {
|
||||||
type C = char;
|
type C = char;
|
||||||
|
|
||||||
fn compareKeyword<'keyword>(&self, kw: impl Keyword<'keyword, C = char>) -> bool {
|
fn compareKeyword<'keyword>(&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,
|
||||||
|
|||||||
@ -7,11 +7,10 @@ impl<'keyword> crate::KeywordComparatorIterator<'keyword, char> for Chars<'keywo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'keyword> crate::Keyword<'keyword> for &'keyword str {
|
impl crate::Keyword<char> for &str {
|
||||||
type C = char;
|
|
||||||
|
|
||||||
fn startComparation(
|
fn startComparation<'keyword>(
|
||||||
&self,
|
&'keyword self,
|
||||||
expectedLen: usize,
|
expectedLen: usize,
|
||||||
) -> Option<impl crate::KeywordComparatorIterator<'keyword, char>> {
|
) -> Option<impl crate::KeywordComparatorIterator<'keyword, char>> {
|
||||||
if (self.len() != expectedLen) {
|
if (self.len() != expectedLen) {
|
||||||
@ -22,11 +21,9 @@ impl<'keyword> crate::Keyword<'keyword> for &'keyword str {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'keyword> crate::Keyword<'keyword> for &'keyword String {
|
impl crate::Keyword<char> for &String {
|
||||||
type C = char;
|
fn startComparation<'keyword>(
|
||||||
|
&'keyword self,
|
||||||
fn startComparation(
|
|
||||||
&self,
|
|
||||||
expectedLen: usize,
|
expectedLen: usize,
|
||||||
) -> Option<impl crate::KeywordComparatorIterator<'keyword, char>> {
|
) -> Option<impl crate::KeywordComparatorIterator<'keyword, char>> {
|
||||||
if (self.len() != expectedLen) {
|
if (self.len() != expectedLen) {
|
||||||
@ -42,13 +39,11 @@ impl<'keyword, C: PartialEq> crate::KeywordComparatorIterator<'keyword, C> for I
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'keyword, T: PartialEq> crate::Keyword<'keyword> for &'keyword [T] {
|
impl<C: PartialEq> crate::Keyword<C> for &[C] {
|
||||||
type C = T;
|
fn startComparation<'keyword>(
|
||||||
|
&'keyword self,
|
||||||
fn startComparation(
|
|
||||||
&self,
|
|
||||||
expectedLen: usize,
|
expectedLen: usize,
|
||||||
) -> Option<impl crate::KeywordComparatorIterator<'keyword, T>> {
|
) -> Option<impl crate::KeywordComparatorIterator<'keyword, C>> {
|
||||||
if (self.len() != expectedLen) {
|
if (self.len() != expectedLen) {
|
||||||
return Option::None;
|
return Option::None;
|
||||||
}
|
}
|
||||||
@ -57,13 +52,11 @@ impl<'keyword, T: PartialEq> crate::Keyword<'keyword> for &'keyword [T] {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'keyword, T: PartialEq, const SZ: usize> crate::Keyword<'keyword> for &'keyword [T; SZ] {
|
impl<C: PartialEq, const SZ: usize> crate::Keyword<C> for &[C; SZ] {
|
||||||
type C = T;
|
fn startComparation<'keyword>(
|
||||||
|
&'keyword self,
|
||||||
fn startComparation(
|
|
||||||
&self,
|
|
||||||
expectedLen: usize,
|
expectedLen: usize,
|
||||||
) -> Option<impl crate::KeywordComparatorIterator<'keyword, T>> {
|
) -> Option<impl crate::KeywordComparatorIterator<'keyword, C>> {
|
||||||
if (self.len() != expectedLen) {
|
if (self.len() != expectedLen) {
|
||||||
return Option::None;
|
return Option::None;
|
||||||
}
|
}
|
||||||
|
|||||||
11
src/lib.rs
11
src/lib.rs
@ -16,17 +16,16 @@ pub trait KeywordComparatorIterator<'keyword, C> {
|
|||||||
fn consume(&mut self, c: C) -> bool;
|
fn consume(&mut self, c: C) -> bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Keyword<'keyword> {
|
pub trait Keyword<C> {
|
||||||
type C;
|
fn startComparation<'keyword>(
|
||||||
fn startComparation(
|
&'keyword self,
|
||||||
&self,
|
|
||||||
expectedLen: usize,
|
expectedLen: usize,
|
||||||
) -> Option<impl KeywordComparatorIterator<'keyword, Self::C>>;
|
) -> Option<impl KeywordComparatorIterator<'keyword, C>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait CollectedSubstring<'source> {
|
pub trait CollectedSubstring<'source> {
|
||||||
type C;
|
type C;
|
||||||
fn compareKeyword<'keyword>(&self, kw: impl Keyword<'keyword, C=Self::C>) -> bool;
|
fn compareKeyword<'keyword>(&self, kw: impl Keyword<Self::C>) -> bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum CollectResult<T> {
|
pub enum CollectResult<T> {
|
||||||
|
|||||||
@ -1,7 +1,10 @@
|
|||||||
#![allow(non_camel_case_types)]
|
#![allow(non_camel_case_types)]
|
||||||
#![allow(non_snake_case)]
|
#![allow(non_snake_case)]
|
||||||
|
|
||||||
use source_stream_0::{CollectResult, CollectedSubstring, Keyword, Pos, Predicate, SourceStream};
|
use source_stream_0::{
|
||||||
|
CollectResult, CollectedSubstring, Keyword, KeywordComparatorIterator, Pos, Predicate,
|
||||||
|
SourceStream,
|
||||||
|
};
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
pub trait SourceStreamConverter_Char<C> {
|
pub trait SourceStreamConverter_Char<C> {
|
||||||
@ -28,10 +31,16 @@ pub trait StreamConverter<'source, 'pos, C, P: Pos<'pos>, CS: CollectedSubstring
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
struct PredicateWrapper<'predicate, 'converter, C, W: SourceStreamConverter_Char<C>, I: Predicate<W::WC>> {
|
struct PredicateWrapper<
|
||||||
|
'predicate,
|
||||||
|
'converter,
|
||||||
|
C,
|
||||||
|
W: SourceStreamConverter_Char<C>,
|
||||||
|
I: Predicate<W::WC>,
|
||||||
|
> {
|
||||||
_orig: &'predicate mut I,
|
_orig: &'predicate mut I,
|
||||||
_converter: &'converter W,
|
_converter: &'converter W,
|
||||||
__phantom: PhantomData<C>
|
__phantom: PhantomData<C>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'predicate, 'converter, C, W: SourceStreamConverter_Char<C>, I: Predicate<W::WC>>
|
impl<'predicate, 'converter, C, W: SourceStreamConverter_Char<C>, I: Predicate<W::WC>>
|
||||||
@ -83,11 +92,15 @@ impl<
|
|||||||
type CS = W::WCS;
|
type CS = W::WCS;
|
||||||
|
|
||||||
fn skip(&mut self, predicate: &mut impl Predicate<W::WC>) -> bool {
|
fn skip(&mut self, predicate: &mut impl Predicate<W::WC>) -> bool {
|
||||||
self._src.skip(&mut PredicateWrapper::wrap(predicate, &self._converter))
|
self._src
|
||||||
|
.skip(&mut PredicateWrapper::wrap(predicate, &self._converter))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn collect(&mut self, predicate: &mut impl Predicate<W::WC>) -> CollectResult<W::WCS> {
|
fn collect(&mut self, predicate: &mut impl Predicate<W::WC>) -> CollectResult<W::WCS> {
|
||||||
match self._src.collect(&mut PredicateWrapper::wrap(predicate, &self._converter)) {
|
match self
|
||||||
|
._src
|
||||||
|
.collect(&mut PredicateWrapper::wrap(predicate, &self._converter))
|
||||||
|
{
|
||||||
CollectResult::EOF => return CollectResult::EOF,
|
CollectResult::EOF => return CollectResult::EOF,
|
||||||
CollectResult::NotMatches => return CollectResult::NotMatches,
|
CollectResult::NotMatches => return CollectResult::NotMatches,
|
||||||
CollectResult::Matches(cs) => return CollectResult::Matches(W::wrapSubstring(cs)),
|
CollectResult::Matches(cs) => return CollectResult::Matches(W::wrapSubstring(cs)),
|
||||||
@ -106,3 +119,71 @@ impl<
|
|||||||
return self._src.nextChar().map(W::wrapChar);
|
return self._src.nextChar().map(W::wrapChar);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct KeywordUnwrapper<
|
||||||
|
'keyword,
|
||||||
|
'converter,
|
||||||
|
C,
|
||||||
|
W: SourceStreamConverter_Char<C>,
|
||||||
|
I: Keyword<W::WC>,
|
||||||
|
> {
|
||||||
|
_orig: &'keyword I,
|
||||||
|
_converter: &'converter W,
|
||||||
|
__phantom: PhantomData<C>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'keyword, 'converter, C, W: SourceStreamConverter_Char<C>, I: Keyword<W::WC>>
|
||||||
|
KeywordUnwrapper<'keyword, 'converter, C, W, I>
|
||||||
|
{
|
||||||
|
fn unwrap(kw: &'keyword I, converter: &'converter W) -> Self {
|
||||||
|
return KeywordUnwrapper {
|
||||||
|
_orig: kw,
|
||||||
|
_converter: converter,
|
||||||
|
__phantom: PhantomData::default(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'keyword, 'converter, C, W: SourceStreamConverter_Char<C>, I: Keyword<W::WC>> Keyword<C>
|
||||||
|
for KeywordUnwrapper<'keyword, 'converter, C, W, I>
|
||||||
|
{
|
||||||
|
fn startComparation<'self_>(
|
||||||
|
&'self_ self,
|
||||||
|
expectedLen: usize,
|
||||||
|
) -> Option<impl KeywordComparatorIterator<'self_, C>> {
|
||||||
|
return self
|
||||||
|
._orig
|
||||||
|
.startComparation(expectedLen)
|
||||||
|
.map(|it| KeywordComparatorWrapper {
|
||||||
|
_orig: it,
|
||||||
|
_converter: self._converter,
|
||||||
|
__phantom: PhantomData::default(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct KeywordComparatorWrapper<
|
||||||
|
'keyword,
|
||||||
|
'converter,
|
||||||
|
C,
|
||||||
|
W: SourceStreamConverter_Char<C>,
|
||||||
|
I: KeywordComparatorIterator<'keyword, W::WC>,
|
||||||
|
> {
|
||||||
|
_orig: I,
|
||||||
|
_converter: &'converter W,
|
||||||
|
__phantom: PhantomData<(&'keyword(), C)>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<
|
||||||
|
'keyword,
|
||||||
|
'converter,
|
||||||
|
C,
|
||||||
|
W: SourceStreamConverter_Char<C>,
|
||||||
|
I: KeywordComparatorIterator<'keyword, W::WC>,
|
||||||
|
> KeywordComparatorIterator<'keyword, C>
|
||||||
|
for KeywordComparatorWrapper<'keyword, 'converter, C, W, I>
|
||||||
|
{
|
||||||
|
fn consume(&mut self, c: C) -> bool {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user