use nom::branch::alt; use nom::character::complete::line_ending; use nom::combinator::eof; use nom::combinator::recognize; use nom::multi::many1; use nom::sequence::tuple; use crate::parser::object::standard_set_object; use crate::parser::parser_context::ChainBehavior; use crate::parser::parser_context::ContextElement; use crate::parser::parser_context::ExitMatcherNode; use crate::parser::parser_with_context::parser_with_context; use super::error::Res; use super::lesser_element::Paragraph; use super::util::blank_line; use super::util::get_consumed; use super::util::trailing_whitespace; use super::Context; pub fn paragraph<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, Paragraph<'s>> { let parser_context = context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { exit_matcher: ChainBehavior::AndParent(Some(¶graph_end)), })); let standard_set_object_matcher = parser_with_context!(standard_set_object)(&parser_context); let (remaining, children) = many1(standard_set_object_matcher)(input)?; let (remaining, _trailing_whitespace) = trailing_whitespace(remaining)?; let source = get_consumed(input, remaining); Ok((remaining, Paragraph { source, children })) } fn paragraph_end<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, &'s str> { // TODO: Other elements should also end paragraphs alt((recognize(tuple((line_ending, many1(blank_line)))), eof))(input) }