From b3b2874cc2f84654c734e17d4ec3c4d3e6315518 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sat, 16 Jul 2022 21:36:06 -0400 Subject: [PATCH] Cleaning up. --- src/parser/nom_context.rs | 20 -------------- src/parser/parser_with_context.rs | 23 +--------------- src/parser/text.rs | 11 ++++---- src/parser/text_element_parser.rs | 45 ++++++++++++------------------- 4 files changed, 24 insertions(+), 75 deletions(-) diff --git a/src/parser/nom_context.rs b/src/parser/nom_context.rs index 174866c..7c61641 100644 --- a/src/parser/nom_context.rs +++ b/src/parser/nom_context.rs @@ -27,24 +27,4 @@ where can_match_link: true, } } - - // pub fn with_no_bold(&self) -> NomContext { - // NomContext { - // fail_matcher: self.fail_matcher.clone(), - // can_match_bold: false, - // can_match_link: self.can_match_link, - // } - // } - - // pub fn with_additional_fail_matcher(&self, additional_matcher: G) -> NomContext - // where - // G: for<'a> FnMut(I) -> IResult, - // { - // let new_fail_matcher = alt((self.fail_matcher, additional_matcher)); - // NomContext { - // fail_matcher: Rc::new(RefCell::new(new_fail_matcher)), - // can_match_bold: self.can_match_bold, - // can_match_link: self.can_match_link, - // } - // } } diff --git a/src/parser/parser_with_context.rs b/src/parser/parser_with_context.rs index c6b1412..bb4a105 100644 --- a/src/parser/parser_with_context.rs +++ b/src/parser/parser_with_context.rs @@ -1,27 +1,6 @@ -// macro_rules! parser_with_context { -// ($name:ident,$typ:ty,$inp:ident,$context:ident,$fnbody:block) => { -// pub fn $name<'c>( -// $context: NomContext<'c, &str, &str, VerboseError<&str>>, -// ) -> impl for<'a> FnMut(&'a str) -> IResult<&'a str, $typ, VerboseError<&'a str>> + 'c { -// |$inp| $fnbody -// } -// }; -// } - -// use nom::error::VerboseError; -// use nom::IResult; -// pub(crate) use parser_with_context; - -// use super::nom_context::NomContext; - macro_rules! parser_with_context { ($target:ident) => { - move |mut context| { - move |i| { - // todo - $target(i, &mut context) - } - } + move |mut context| move |i| $target(i, &mut context) }; } pub(crate) use parser_with_context; diff --git a/src/parser/text.rs b/src/parser/text.rs index ef3b968..5bbe3a5 100644 --- a/src/parser/text.rs +++ b/src/parser/text.rs @@ -24,6 +24,7 @@ use nom::sequence::tuple; use nom::IResult; use super::nom_context::NomContext; +use super::text_element_parser::paragraph; pub type Res = IResult>; @@ -127,11 +128,11 @@ pub fn link_end(input: &str) -> Res<&str, TextElement> { map(symbol("]"), TextElement::Symbol)(input) } -pub fn paragraph(input: &str) -> Res<&str, (Vec, &str)> { - // let initial_context = NomContext::new(¶graph_end); - // many_till(text_element(initial_context), paragraph_end)(input) - todo!() -} +// pub fn paragraph(input: &str) -> Res<&str, (Vec, &str)> { +// // let initial_context = NomContext::new(¶graph_end); +// // many_till(text_element(initial_context), paragraph_end)(input) +// todo!() +// } pub fn paragraph_end(input: &str) -> Res<&str, &str> { recognize(tuple((map(line_break, TextElement::LineBreak), blank_line)))(input) diff --git a/src/parser/text_element_parser.rs b/src/parser/text_element_parser.rs index ce37405..3d2bf2b 100644 --- a/src/parser/text_element_parser.rs +++ b/src/parser/text_element_parser.rs @@ -3,7 +3,6 @@ use crate::parser::parser_with_context::parser_with_context; use crate::parser::text::paragraph_end; use super::nom_context::NomContext; -// use super::parser_with_context::parser_with_context; use super::text::line_break; use super::text::space; use super::text::span; @@ -17,30 +16,6 @@ use nom::error::VerboseError; use nom::multi::many_till; use nom::IResult; -// parser_with_context!(text_element, TextElement, i, context, { -// // not(|j| { -// // // tood -// // (context.fail_matcher)(j) -// // })(i)?; -// // not(|i| (context.fail_matcher)(i))(i)?; -// alt(( -// // map( -// // BoldParser::new(slf.context.fail_matcher.clone()), -// // TextElement::Bold, -// // ), -// // map( -// // LinkParser::new(slf.context.fail_matcher.clone()), -// // TextElement::Link, -// // ), -// map(span, TextElement::Span), -// map(symbol("*"), TextElement::Symbol), -// map(symbol("["), TextElement::Symbol), -// map(symbol("]"), TextElement::Symbol), -// map(space, TextElement::Space), -// map(line_break, TextElement::LineBreak), -// ))(i) -// }); - pub fn flat_text_element<'a, F>( i: &'a str, context: &mut NomContext, @@ -48,9 +23,23 @@ pub fn flat_text_element<'a, F>( where F: for<'b> FnMut(&'b str) -> IResult<&'b str, &'b str, VerboseError<&'b str>>, { - // not(context.fail_matcher)(i)?; - // todo - todo!() + not(&mut context.fail_matcher)(i)?; + alt(( + // map( + // BoldParser::new(slf.context.fail_matcher.clone()), + // TextElement::Bold, + // ), + // map( + // LinkParser::new(slf.context.fail_matcher.clone()), + // TextElement::Link, + // ), + map(span, TextElement::Span), + map(symbol("*"), TextElement::Symbol), + map(symbol("["), TextElement::Symbol), + map(symbol("]"), TextElement::Symbol), + map(space, TextElement::Space), + map(line_break, TextElement::LineBreak), + ))(i) } pub fn paragraph(input: &str) -> Res<&str, (Vec, &str)> {