2022-07-16 03:26:49 +00:00
|
|
|
//! A single element of text.
|
2022-12-16 05:53:29 +00:00
|
|
|
use super::combinator::context_many1;
|
2022-12-18 07:59:41 +00:00
|
|
|
use super::error::Res;
|
2022-12-18 07:53:26 +00:00
|
|
|
use super::paragraph::paragraph;
|
2022-12-18 07:16:28 +00:00
|
|
|
use super::parser_context::ContextElement;
|
|
|
|
use super::parser_context::ContextTree;
|
2022-12-16 06:35:49 +00:00
|
|
|
use super::text::Paragraph;
|
2022-12-04 04:53:52 +00:00
|
|
|
use super::token::Token;
|
2022-12-04 02:13:42 +00:00
|
|
|
use super::Context;
|
2022-07-16 03:26:49 +00:00
|
|
|
use nom::IResult;
|
2022-10-15 00:17:48 +00:00
|
|
|
|
2022-12-11 04:49:02 +00:00
|
|
|
type UnboundMatcher<'r, 's, I, O, E> = dyn Fn(Context<'r, 's>, I) -> IResult<I, O, E>;
|
2022-12-04 03:44:53 +00:00
|
|
|
|
2022-12-16 06:35:49 +00:00
|
|
|
pub fn document(input: &str) -> Res<&str, Vec<Paragraph>> {
|
2022-12-11 04:49:02 +00:00
|
|
|
let initial_context: ContextTree<'_, '_> = ContextTree::new();
|
2022-12-16 06:35:49 +00:00
|
|
|
let (remaining, tokens) = context_many1(&initial_context, paragraph)(input)?;
|
2022-12-18 07:05:21 +00:00
|
|
|
let paragraphs = tokens
|
|
|
|
.into_iter()
|
|
|
|
.map(|token| match token {
|
2022-12-16 06:35:49 +00:00
|
|
|
Token::TextElement(_) => unreachable!(),
|
|
|
|
Token::Paragraph(paragraph) => paragraph,
|
2022-12-18 07:05:21 +00:00
|
|
|
})
|
|
|
|
.collect();
|
2022-12-16 06:35:49 +00:00
|
|
|
Ok((remaining, paragraphs))
|
2022-11-27 00:14:19 +00:00
|
|
|
}
|