Cleaning up.
This commit is contained in:
parent
8357837571
commit
b3b2874cc2
@ -27,24 +27,4 @@ where
|
||||
can_match_link: true,
|
||||
}
|
||||
}
|
||||
|
||||
// pub fn with_no_bold(&self) -> NomContext<I, O, E> {
|
||||
// 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<G, I, O, E>
|
||||
// where
|
||||
// G: for<'a> FnMut(I) -> IResult<I, O, E>,
|
||||
// {
|
||||
// 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,
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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<T, U> = IResult<T, U, VerboseError<T>>;
|
||||
|
||||
@ -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<TextElement>, &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<TextElement>, &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)
|
||||
|
@ -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<F>,
|
||||
@ -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<TextElement>, &str)> {
|
||||
|
Loading…
Reference in New Issue
Block a user