Impl missing traits.

This commit is contained in:
Tom Alexander 2023-08-22 23:32:27 -04:00
parent c475dce6da
commit b7a5dd48ea
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
1 changed files with 32 additions and 11 deletions

View File

@ -12,7 +12,7 @@ use nom::Slice;
pub struct OrgSource<'s> {
full_source: &'s str,
start: usize,
end: usize, //exclusive
end: usize, // exclusive
preceding_line_break: Option<usize>,
}
@ -113,7 +113,7 @@ impl<'s> std::fmt::Display for OrgSource<'s> {
impl<'s> InputLength for OrgSource<'s> {
fn input_len(&self) -> usize {
todo!()
self.end - self.start
}
}
@ -125,28 +125,28 @@ impl<'s> InputIter for OrgSource<'s> {
type IterElem = <&'s str as InputIter>::IterElem;
fn iter_indices(&self) -> Self::Iter {
todo!()
Into::<&str>::into(self).char_indices()
}
fn iter_elements(&self) -> Self::IterElem {
todo!()
Into::<&str>::into(self).iter_elements()
}
fn position<P>(&self, predicate: P) -> Option<usize>
where
P: Fn(Self::Item) -> bool,
{
todo!()
Into::<&str>::into(self).position(predicate)
}
fn slice_index(&self, count: usize) -> Result<usize, nom::Needed> {
todo!()
Into::<&str>::into(self).slice_index(count)
}
}
impl<'s> Offset for OrgSource<'s> {
fn offset(&self, second: &Self) -> usize {
todo!()
second.start - self.start
}
}
@ -160,7 +160,10 @@ impl<'s> InputTakeAtPosition for OrgSource<'s> {
where
P: Fn(Self::Item) -> bool,
{
todo!()
match Into::<&str>::into(self).position(predicate) {
Some(idx) => Ok(self.take_split(idx)),
None => Err(nom::Err::Incomplete(nom::Needed::new(1))),
}
}
fn split_at_position1<P, E: nom::error::ParseError<Self>>(
@ -171,7 +174,11 @@ impl<'s> InputTakeAtPosition for OrgSource<'s> {
where
P: Fn(Self::Item) -> bool,
{
todo!()
match Into::<&str>::into(self).position(predicate) {
Some(0) => Err(nom::Err::Error(E::from_error_kind(self.clone(), e))),
Some(idx) => Ok(self.take_split(idx)),
None => Err(nom::Err::Incomplete(nom::Needed::new(1))),
}
}
fn split_at_position_complete<P, E: nom::error::ParseError<Self>>(
@ -181,7 +188,10 @@ impl<'s> InputTakeAtPosition for OrgSource<'s> {
where
P: Fn(Self::Item) -> bool,
{
todo!()
match self.split_at_position(predicate) {
Err(nom::Err::Incomplete(_)) => Ok(self.take_split(self.input_len())),
res => res,
}
}
fn split_at_position1_complete<P, E: nom::error::ParseError<Self>>(
@ -192,7 +202,18 @@ impl<'s> InputTakeAtPosition for OrgSource<'s> {
where
P: Fn(Self::Item) -> bool,
{
todo!()
let window = Into::<&str>::into(self);
match window.position(predicate) {
Some(0) => Err(nom::Err::Error(E::from_error_kind(self.clone(), e))),
Some(n) => Ok(self.take_split(n)),
None => {
if window.input_len() == 0 {
Err(nom::Err::Error(E::from_error_kind(self.clone(), e)))
} else {
Ok(self.take_split(self.input_len()))
}
}
}
}
}