//! A single element of text. use super::combinator::context_many1; use super::error::Res; use super::paragraph::paragraph; use super::parser_context::ContextTree; use super::token::Paragraph; use super::token::Token; use super::Context; use nom::IResult; type UnboundMatcher<'r, 's, I, O, E> = dyn Fn(Context<'r, 's>, I) -> IResult; pub fn document(input: &str) -> Res<&str, Vec> { let initial_context: ContextTree<'_, '_> = ContextTree::new(); let (remaining, tokens) = context_many1(&initial_context, paragraph)(input)?; let paragraphs = tokens .into_iter() .map(|token| match token { Token::TextElement(_) => unreachable!(), Token::Paragraph(paragraph) => paragraph, }) .collect(); Ok((remaining, paragraphs)) }