From 4af09a69a1060297bf678f2bcd76257f2ce43ed9 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Thu, 15 Dec 2022 21:24:53 -0500 Subject: [PATCH] Rename fail matcher to exit matcher. --- src/parser/nom_context.rs | 12 ++++++------ src/parser/text_element_parser.rs | 26 +++++++++++++------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/parser/nom_context.rs b/src/parser/nom_context.rs index 978e6cf..e0ad437 100644 --- a/src/parser/nom_context.rs +++ b/src/parser/nom_context.rs @@ -43,7 +43,7 @@ impl<'r, 's> ContextTree<'r, 's> { self.tree.iter() } - pub fn check_fail_matcher( + pub fn check_exit_matcher( &'r self, i: &'s str, ) -> IResult<&'s str, &'s str, VerboseError<&'s str>> { @@ -54,8 +54,8 @@ impl<'r, 's> ContextTree<'r, 's> { .get_data() .expect("While looop proves its Some()"); match context_element { - ContextElement::FailMatcherNode(fail_matcher) => { - match fail_matcher.fail_matcher { + ContextElement::ExitMatcherNode(exit_matcher) => { + match exit_matcher.exit_matcher { ChainBehavior::AndParent(Some(matcher)) => { let local_result = matcher(self, i); if local_result.is_ok() { @@ -92,14 +92,14 @@ impl<'r, 's> ContextTree<'r, 's> { #[derive(Debug)] pub enum ContextElement<'r, 's> { - FailMatcherNode(FailMatcherNode<'r>), + ExitMatcherNode(ExitMatcherNode<'r>), PreviousElementNode(PreviousElementNode<'s>), StartOfParagraph, } #[derive(Debug)] -pub struct FailMatcherNode<'r> { - pub fail_matcher: ChainBehavior<'r>, +pub struct ExitMatcherNode<'r> { + pub exit_matcher: ChainBehavior<'r>, } #[derive(Debug)] diff --git a/src/parser/text_element_parser.rs b/src/parser/text_element_parser.rs index 750a1d0..569e347 100644 --- a/src/parser/text_element_parser.rs +++ b/src/parser/text_element_parser.rs @@ -5,7 +5,7 @@ use crate::parser::text::paragraph_end; use super::nom_context::ChainBehavior; use super::nom_context::ContextElement; use super::nom_context::ContextTree; -use super::nom_context::FailMatcherNode; +use super::nom_context::ExitMatcherNode; use super::nom_context::PreviousElementNode; use super::text::bold_end; use super::text::bold_start; @@ -66,7 +66,7 @@ where let context_element = context_element.expect("We only pop off context elements created in this function, so they are all Some()"); current_context = next_context; match context_element { - ContextElement::FailMatcherNode(_) => {} + ContextElement::ExitMatcherNode(_) => {} ContextElement::StartOfParagraph => {} ContextElement::PreviousElementNode(PreviousElementNode { element: token, @@ -127,7 +127,7 @@ fn can_start_bold<'s, 'r>(context: Context<'r, 's>) -> bool { loop { if let Some((i, ctx)) = context_iterator.next() { match ctx.get_data() { - ContextElement::FailMatcherNode(_) => {} + ContextElement::ExitMatcherNode(_) => {} ContextElement::PreviousElementNode(previous_element_node) => { match &previous_element_node.element { Token::TextElement(text_element) => { @@ -169,11 +169,11 @@ pub fn context_bold_start<'s, 'r>( pub fn context_bold_end<'s, 'r>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, &'s str> { let (remaining, actual_match) = recognize(bold_end)(input)?; peek(alt(( - // Must have whitespace after the end asterisk or it must be the end of that section (as checked by the fail matcher) + // Must have whitespace after the end asterisk or it must be the end of that section (as checked by the exit matcher) tag(" "), tag("\t"), tag("\n"), - |i| context.check_fail_matcher(i), + |i| context.check_exit_matcher(i), )))(remaining)?; Ok((remaining, actual_match)) @@ -187,8 +187,8 @@ pub fn paragraph<'s, 'r>( not(eof)(i)?; let paragraph_context = context .with_additional_node(ContextElement::StartOfParagraph) - .with_additional_node(ContextElement::FailMatcherNode(FailMatcherNode { - fail_matcher: ChainBehavior::AndParent(Some(&context_paragraph_end)), + .with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { + exit_matcher: ChainBehavior::AndParent(Some(&context_paragraph_end)), })); let (remaining, (many, till)) = context_many_till(¶graph_context, flat_text_element, context_paragraph_end)(i)?; @@ -205,7 +205,7 @@ fn flat_text_element<'s, 'r>( context: Context<'r, 's>, i: &'s str, ) -> Res<&'s str, TextElement<'s>> { - not(|i| context.check_fail_matcher(i))(i)?; + not(|i| context.check_exit_matcher(i))(i)?; let bold_matcher = parser_with_context!(flat_bold)(&context); let link_matcher = parser_with_context!(flat_link)(&context); @@ -225,8 +225,8 @@ fn flat_text_element<'s, 'r>( fn flat_bold<'s, 'r>(context: Context<'r, 's>, i: &'s str) -> Res<&'s str, Bold<'s>> { let bold_start = parser_with_context!(context_bold_start)(&context); let nom_context = - context.with_additional_node(ContextElement::FailMatcherNode(FailMatcherNode { - fail_matcher: ChainBehavior::AndParent(Some(&context_bold_end)), + context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { + exit_matcher: ChainBehavior::AndParent(Some(&context_bold_end)), })); let (remaining, captured) = recognize(tuple((bold_start, |i| { context_many_till(&nom_context, flat_text_element, context_bold_end)(i) @@ -241,10 +241,10 @@ fn recognize_link_end<'s, 'r>(context: Context<'r, 's>, input: &'s str) -> Res<& fn flat_link<'s, 'r>(context: Context<'r, 's>, i: &'s str) -> Res<&'s str, Link<'s>> { let nom_context = - context.with_additional_node(ContextElement::FailMatcherNode(FailMatcherNode { - fail_matcher: ChainBehavior::AndParent(Some(&recognize_link_end)), + context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { + exit_matcher: ChainBehavior::AndParent(Some(&recognize_link_end)), })); - // let nom_context = context.with_additional_fail_matcher(&recognize_link_end); + // let nom_context = context.with_additional_exit_matcher(&recognize_link_end); let text_element_parser = parser_with_context!(flat_text_element)(&nom_context); let (remaining, captured) = recognize(tuple(( link_start,