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()
|
self.tree.iter()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn check_fail_matcher(
|
pub fn check_exit_matcher(
|
||||||
&'r self,
|
&'r self,
|
||||||
i: &'s str,
|
i: &'s str,
|
||||||
) -> IResult<&'s str, &'s str, VerboseError<&'s str>> {
|
) -> IResult<&'s str, &'s str, VerboseError<&'s str>> {
|
||||||
@ -54,8 +54,8 @@ impl<'r, 's> ContextTree<'r, 's> {
|
|||||||
.get_data()
|
.get_data()
|
||||||
.expect("While looop proves its Some()");
|
.expect("While looop proves its Some()");
|
||||||
match context_element {
|
match context_element {
|
||||||
ContextElement::FailMatcherNode(fail_matcher) => {
|
ContextElement::ExitMatcherNode(exit_matcher) => {
|
||||||
match fail_matcher.fail_matcher {
|
match exit_matcher.exit_matcher {
|
||||||
ChainBehavior::AndParent(Some(matcher)) => {
|
ChainBehavior::AndParent(Some(matcher)) => {
|
||||||
let local_result = matcher(self, i);
|
let local_result = matcher(self, i);
|
||||||
if local_result.is_ok() {
|
if local_result.is_ok() {
|
||||||
@ -92,14 +92,14 @@ impl<'r, 's> ContextTree<'r, 's> {
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum ContextElement<'r, 's> {
|
pub enum ContextElement<'r, 's> {
|
||||||
FailMatcherNode(FailMatcherNode<'r>),
|
ExitMatcherNode(ExitMatcherNode<'r>),
|
||||||
PreviousElementNode(PreviousElementNode<'s>),
|
PreviousElementNode(PreviousElementNode<'s>),
|
||||||
StartOfParagraph,
|
StartOfParagraph,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct FailMatcherNode<'r> {
|
pub struct ExitMatcherNode<'r> {
|
||||||
pub fail_matcher: ChainBehavior<'r>,
|
pub exit_matcher: ChainBehavior<'r>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -5,7 +5,7 @@ use crate::parser::text::paragraph_end;
|
|||||||
use super::nom_context::ChainBehavior;
|
use super::nom_context::ChainBehavior;
|
||||||
use super::nom_context::ContextElement;
|
use super::nom_context::ContextElement;
|
||||||
use super::nom_context::ContextTree;
|
use super::nom_context::ContextTree;
|
||||||
use super::nom_context::FailMatcherNode;
|
use super::nom_context::ExitMatcherNode;
|
||||||
use super::nom_context::PreviousElementNode;
|
use super::nom_context::PreviousElementNode;
|
||||||
use super::text::bold_end;
|
use super::text::bold_end;
|
||||||
use super::text::bold_start;
|
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()");
|
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;
|
current_context = next_context;
|
||||||
match context_element {
|
match context_element {
|
||||||
ContextElement::FailMatcherNode(_) => {}
|
ContextElement::ExitMatcherNode(_) => {}
|
||||||
ContextElement::StartOfParagraph => {}
|
ContextElement::StartOfParagraph => {}
|
||||||
ContextElement::PreviousElementNode(PreviousElementNode {
|
ContextElement::PreviousElementNode(PreviousElementNode {
|
||||||
element: token,
|
element: token,
|
||||||
@ -127,7 +127,7 @@ fn can_start_bold<'s, 'r>(context: Context<'r, 's>) -> bool {
|
|||||||
loop {
|
loop {
|
||||||
if let Some((i, ctx)) = context_iterator.next() {
|
if let Some((i, ctx)) = context_iterator.next() {
|
||||||
match ctx.get_data() {
|
match ctx.get_data() {
|
||||||
ContextElement::FailMatcherNode(_) => {}
|
ContextElement::ExitMatcherNode(_) => {}
|
||||||
ContextElement::PreviousElementNode(previous_element_node) => {
|
ContextElement::PreviousElementNode(previous_element_node) => {
|
||||||
match &previous_element_node.element {
|
match &previous_element_node.element {
|
||||||
Token::TextElement(text_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> {
|
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)?;
|
let (remaining, actual_match) = recognize(bold_end)(input)?;
|
||||||
peek(alt((
|
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(" "),
|
||||||
tag("\t"),
|
tag("\t"),
|
||||||
tag("\n"),
|
tag("\n"),
|
||||||
|i| context.check_fail_matcher(i),
|
|i| context.check_exit_matcher(i),
|
||||||
)))(remaining)?;
|
)))(remaining)?;
|
||||||
|
|
||||||
Ok((remaining, actual_match))
|
Ok((remaining, actual_match))
|
||||||
@ -187,8 +187,8 @@ pub fn paragraph<'s, 'r>(
|
|||||||
not(eof)(i)?;
|
not(eof)(i)?;
|
||||||
let paragraph_context = context
|
let paragraph_context = context
|
||||||
.with_additional_node(ContextElement::StartOfParagraph)
|
.with_additional_node(ContextElement::StartOfParagraph)
|
||||||
.with_additional_node(ContextElement::FailMatcherNode(FailMatcherNode {
|
.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
|
||||||
fail_matcher: ChainBehavior::AndParent(Some(&context_paragraph_end)),
|
exit_matcher: ChainBehavior::AndParent(Some(&context_paragraph_end)),
|
||||||
}));
|
}));
|
||||||
let (remaining, (many, till)) =
|
let (remaining, (many, till)) =
|
||||||
context_many_till(¶graph_context, flat_text_element, context_paragraph_end)(i)?;
|
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>,
|
context: Context<'r, 's>,
|
||||||
i: &'s str,
|
i: &'s str,
|
||||||
) -> Res<&'s str, TextElement<'s>> {
|
) -> 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 bold_matcher = parser_with_context!(flat_bold)(&context);
|
||||||
let link_matcher = parser_with_context!(flat_link)(&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>> {
|
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 bold_start = parser_with_context!(context_bold_start)(&context);
|
||||||
let nom_context =
|
let nom_context =
|
||||||
context.with_additional_node(ContextElement::FailMatcherNode(FailMatcherNode {
|
context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
|
||||||
fail_matcher: ChainBehavior::AndParent(Some(&context_bold_end)),
|
exit_matcher: ChainBehavior::AndParent(Some(&context_bold_end)),
|
||||||
}));
|
}));
|
||||||
let (remaining, captured) = recognize(tuple((bold_start, |i| {
|
let (remaining, captured) = recognize(tuple((bold_start, |i| {
|
||||||
context_many_till(&nom_context, flat_text_element, context_bold_end)(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>> {
|
fn flat_link<'s, 'r>(context: Context<'r, 's>, i: &'s str) -> Res<&'s str, Link<'s>> {
|
||||||
let nom_context =
|
let nom_context =
|
||||||
context.with_additional_node(ContextElement::FailMatcherNode(FailMatcherNode {
|
context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
|
||||||
fail_matcher: ChainBehavior::AndParent(Some(&recognize_link_end)),
|
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 text_element_parser = parser_with_context!(flat_text_element)(&nom_context);
|
||||||
let (remaining, captured) = recognize(tuple((
|
let (remaining, captured) = recognize(tuple((
|
||||||
link_start,
|
link_start,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user