From b20568c09e54add10d2de5454ce0f4074c34a821 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sat, 3 Dec 2022 23:53:52 -0500 Subject: [PATCH] Clone issue. --- src/parser/mod.rs | 1 + src/parser/nom_context.rs | 3 ++- src/parser/text.rs | 2 +- src/parser/text_element_parser.rs | 4 +++- src/parser/token.rs | 12 ++++++++++++ 5 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 src/parser/token.rs diff --git a/src/parser/mod.rs b/src/parser/mod.rs index c18823da..0b76a1c5 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -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>; diff --git a/src/parser/nom_context.rs b/src/parser/nom_context.rs index 3e566bf8..25cb1903 100644 --- a/src/parser/nom_context.rs +++ b/src/parser/nom_context.rs @@ -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)] diff --git a/src/parser/text.rs b/src/parser/text.rs index 0b7a9580..b328a7ed 100644 --- a/src/parser/text.rs +++ b/src/parser/text.rs @@ -33,7 +33,7 @@ use super::text_element_parser::paragraph; pub type Res = IResult>; -#[derive(Debug)] +#[derive(Debug, Clone)] pub enum TextElement<'a> { Span(Span<'a>), Space(Space<'a>), diff --git a/src/parser/text_element_parser.rs b/src/parser/text_element_parser.rs index baa028c0..b5f3d345 100644 --- a/src/parser/text_element_parser.rs +++ b/src/parser/text_element_parser.rs @@ -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; -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, F), E> + 'r where + O: Into>, I: Clone + InputLength, E: ParseError, M: Fn(Context<'r>, I) -> IResult + 'r, diff --git a/src/parser/token.rs b/src/parser/token.rs new file mode 100644 index 00000000..64eb7837 --- /dev/null +++ b/src/parser/token.rs @@ -0,0 +1,12 @@ +use super::text::TextElement; + +#[derive(Debug)] +pub enum Token<'a> { + TextElement(TextElement<'a>), +} + +impl<'a> Into> for TextElement<'a> { + fn into(self) -> Token<'a> { + Token::TextElement(self) + } +}