From add717071c305ce2ca97c26933ba7f3816bd4bce Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Fri, 14 Oct 2022 20:25:10 -0400 Subject: [PATCH] Using a mutable reference breaks clone. --- src/parser/nom_context.rs | 5 ++--- src/parser/text.rs | 2 +- src/parser/text_element_parser.rs | 1 + 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/parser/nom_context.rs b/src/parser/nom_context.rs index 1dab499d..aa2a905b 100644 --- a/src/parser/nom_context.rs +++ b/src/parser/nom_context.rs @@ -2,9 +2,8 @@ use nom::branch::alt; use nom::error::VerboseError; use nom::IResult; -#[derive(Clone)] pub struct NomContext<'a> { - pub fail_matcher: &'a dyn FnMut(&str) -> IResult<&str, &str, VerboseError<&str>>, + pub fail_matcher: &'a mut dyn FnMut(&str) -> IResult<&str, &str, VerboseError<&str>>, /// You can't have nested bolds or links in org-mode pub can_match_bold: bool, pub can_match_link: bool, @@ -12,7 +11,7 @@ pub struct NomContext<'a> { impl<'a> NomContext<'a> { pub fn new( - fail_matcher: &'a dyn FnMut(&str) -> IResult<&str, &str, VerboseError<&str>>, + fail_matcher: &'a mut dyn FnMut(&str) -> IResult<&str, &str, VerboseError<&str>>, ) -> Self { NomContext { fail_matcher, diff --git a/src/parser/text.rs b/src/parser/text.rs index ae7af927..1826228b 100644 --- a/src/parser/text.rs +++ b/src/parser/text.rs @@ -133,7 +133,7 @@ pub fn paragraph_end(input: &str) -> Res<&str, &str> { } pub fn document(input: &str) -> Res<&str, Vec<(Vec, &str)>> { - let initial_context = NomContext::new(¶graph_end); + let initial_context = NomContext::new(&mut paragraph_end); todo!() // many1(parser_with_context!(paragraph)(initial_context))(input) } diff --git a/src/parser/text_element_parser.rs b/src/parser/text_element_parser.rs index a51e3bc3..8dcb96ba 100644 --- a/src/parser/text_element_parser.rs +++ b/src/parser/text_element_parser.rs @@ -25,5 +25,6 @@ fn flat_text_element<'s, 'r>( i: &'s str, context: &'r mut NomContext, ) -> Res<&'s str, TextElement<'s>> { + not(&mut context.fail_matcher)(i)?; todo!() }