Rename fail matcher to exit matcher.
This commit is contained in:
parent
0c676c44c2
commit
4af09a69a1
@ -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)]
|
||||
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user