Going to try to make the functions in the context more generic.
This commit is contained in:
@@ -20,62 +20,3 @@ use nom::error::VerboseError;
|
||||
use nom::multi::many_till;
|
||||
use nom::sequence::tuple;
|
||||
use nom::IResult;
|
||||
|
||||
pub fn flat_text_element<'a, F>(
|
||||
i: &'a str,
|
||||
context: &mut NomContext<F>,
|
||||
) -> Res<&'a str, TextElement<'a>>
|
||||
where
|
||||
F: for<'b> FnMut(&'b str) -> IResult<&'b str, &'b str, VerboseError<&'b str>>
|
||||
+ std::clone::Clone,
|
||||
{
|
||||
not(&mut context.fail_matcher)(i)?;
|
||||
// if context.can_match_bold {
|
||||
// if let Ok(v) = parser_with_context!(flat_bold)(context.clone())(i) {
|
||||
// return Ok(v);
|
||||
// }
|
||||
// }
|
||||
// if context.can_match_link {
|
||||
// // todo
|
||||
// }
|
||||
alt((
|
||||
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_bold<'a, F>(i: &'a str, context: &mut NomContext<F>) -> Res<&'a str, TextElement<'a>>
|
||||
// where
|
||||
// F: for<'b> FnMut(&'b str) -> IResult<&'b str, &'b str, VerboseError<&'b str>>,
|
||||
// F: Clone,
|
||||
// {
|
||||
// not(&mut context.fail_matcher)(i)?;
|
||||
// let new_context = context
|
||||
// .without_bold()
|
||||
// .with_additional_fail_matcher(|i| recognize(bold_end)(i));
|
||||
// let text_element_parser = parser_with_context!(flat_text_element)(new_context);
|
||||
// map(
|
||||
// recognize(tuple((
|
||||
// bold_start,
|
||||
// many_till(text_element_parser, bold_end),
|
||||
// bold_end,
|
||||
// ))),
|
||||
// |body| TextElement::Bold(Bold { contents: body }),
|
||||
// )(i)
|
||||
// }
|
||||
|
||||
pub fn paragraph<'a, F>(
|
||||
i: &'a str,
|
||||
context: &mut NomContext<F>,
|
||||
) -> Res<&'a str, (Vec<TextElement<'a>>, &'a str)>
|
||||
where
|
||||
F: for<'b> FnMut(&'b str) -> IResult<&'b str, &'b str, VerboseError<&'b str>>,
|
||||
F: Clone,
|
||||
{
|
||||
let text_element_parser = parser_with_context!(flat_text_element)(context.clone());
|
||||
many_till(text_element_parser, paragraph_end)(i)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user