Lifetime issue.

This commit is contained in:
Tom Alexander 2023-08-22 22:57:44 -04:00
parent cda49c628c
commit 6d1675fa00
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
2 changed files with 100 additions and 1 deletions

View File

@ -1,10 +1,14 @@
use std::ops::RangeBounds;
use nom::Compare;
use nom::InputIter;
use nom::InputLength;
use nom::InputTake;
use nom::InputTakeAtPosition;
use nom::Offset;
use nom::Slice;
#[derive(Debug)]
#[derive(Debug, Copy, Clone)]
pub struct OrgSource<'s> {
full_source: &'s str,
start: usize,
@ -107,6 +111,91 @@ impl<'s> std::fmt::Display for OrgSource<'s> {
}
}
impl<'s> InputLength for OrgSource<'s> {
fn input_len(&self) -> usize {
todo!()
}
}
impl<'s> InputIter for OrgSource<'s> {
type Item = <&'s str as InputIter>::Item;
type Iter = <&'s str as InputIter>::Iter;
type IterElem = <&'s str as InputIter>::IterElem;
fn iter_indices(&self) -> Self::Iter {
todo!()
}
fn iter_elements(&self) -> Self::IterElem {
todo!()
}
fn position<P>(&self, predicate: P) -> Option<usize>
where
P: Fn(Self::Item) -> bool,
{
todo!()
}
fn slice_index(&self, count: usize) -> Result<usize, nom::Needed> {
todo!()
}
}
impl<'s> Offset for OrgSource<'s> {
fn offset(&self, second: &Self) -> usize {
todo!()
}
}
impl<'s> InputTakeAtPosition for OrgSource<'s> {
type Item = <&'s str as InputTakeAtPosition>::Item;
fn split_at_position<P, E: nom::error::ParseError<Self>>(
&self,
predicate: P,
) -> nom::IResult<Self, Self, E>
where
P: Fn(Self::Item) -> bool,
{
todo!()
}
fn split_at_position1<P, E: nom::error::ParseError<Self>>(
&self,
predicate: P,
e: nom::error::ErrorKind,
) -> nom::IResult<Self, Self, E>
where
P: Fn(Self::Item) -> bool,
{
todo!()
}
fn split_at_position_complete<P, E: nom::error::ParseError<Self>>(
&self,
predicate: P,
) -> nom::IResult<Self, Self, E>
where
P: Fn(Self::Item) -> bool,
{
todo!()
}
fn split_at_position1_complete<P, E: nom::error::ParseError<Self>>(
&self,
predicate: P,
e: nom::error::ErrorKind,
) -> nom::IResult<Self, Self, E>
where
P: Fn(Self::Item) -> bool,
{
todo!()
}
}
#[cfg(test)]
mod tests {
use super::*;

View File

@ -14,6 +14,7 @@ use nom::multi::many0;
use nom::multi::many_till;
use nom::sequence::tuple;
use super::org_source::OrgSource;
use super::parser_context::ContextElement;
use super::Context;
use crate::error::CustomError;
@ -113,6 +114,15 @@ pub fn blank_line(input: &str) -> Res<&str, &str> {
recognize(tuple((space0, alt((line_ending, eof)))))(input)
}
/// A line containing only whitespace and then a line break
///
/// It is up to the caller to ensure this is called at the start of a line.
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
pub fn new_blank_line<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>> {
not(eof)(input)?;
recognize(tuple((space0, alt((line_ending, eof)))))(input)
}
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
pub fn element_trailing_whitespace<'r, 's>(
context: Context<'r, 's>,