Clone issue.

This commit is contained in:
Tom Alexander 2022-12-03 23:53:52 -05:00
parent 96aca6b537
commit b20568c09e
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
5 changed files with 19 additions and 3 deletions

View File

@ -3,5 +3,6 @@ mod nom_context;
mod parser_with_context;
mod text;
mod text_element_parser;
mod token;
pub use text_element_parser::document;
type Context<'r> = &'r nom_context::ContextTree<'r>;

View File

@ -4,6 +4,7 @@ use nom::error::VerboseError;
use nom::IResult;
use super::list::List;
use super::token::Token;
type Matcher = dyn for<'s> Fn(&'s str) -> IResult<&'s str, &'s str, VerboseError<&'s str>>;
@ -81,7 +82,7 @@ pub struct FailMatcherNode<'r> {
#[derive(Debug, Clone)]
pub struct PreviousElementNode<'r> {
pub dummy: &'r str,
pub element: Token<'r>,
}
#[derive(Clone)]

View File

@ -33,7 +33,7 @@ use super::text_element_parser::paragraph;
pub type Res<T, U> = IResult<T, U, VerboseError<T>>;
#[derive(Debug)]
#[derive(Debug, Clone)]
pub enum TextElement<'a> {
Span(Span<'a>),
Space(Space<'a>),

View File

@ -21,6 +21,7 @@ use super::text::Bold;
use super::text::Link;
use super::text::Res;
use super::text::TextElement;
use super::token::Token;
use super::Context;
use nom::branch::alt;
use nom::combinator::eof;
@ -41,12 +42,13 @@ use tracing::trace;
type UnboundMatcher<'r, I, O, E> = dyn Fn(Context<'r>, I) -> IResult<I, O, E>;
fn context_many_till<'r, I, O, E, F, M, T>(
fn context_many_till<'r, 'x, I, O, E, F, M, T>(
context: Context<'r>,
mut many_matcher: M,
mut till_matcher: T,
) -> impl FnMut(I) -> IResult<I, (Vec<O>, F), E> + 'r
where
O: Into<Token<'x>>,
I: Clone + InputLength,
E: ParseError<I>,
M: Fn(Context<'r>, I) -> IResult<I, O, E> + 'r,

12
src/parser/token.rs Normal file
View File

@ -0,0 +1,12 @@
use super::text::TextElement;
#[derive(Debug)]
pub enum Token<'a> {
TextElement(TextElement<'a>),
}
impl<'a> Into<Token<'a>> for TextElement<'a> {
fn into(self) -> Token<'a> {
Token::TextElement(self)
}
}