30 lines
1005 B
Rust
30 lines
1005 B
Rust
//! A single element of text.
|
|
use super::combinator::context_many1;
|
|
use super::error::Res;
|
|
use super::paragraph::paragraph;
|
|
use super::parser_context::ContextElement;
|
|
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<I, O, E>;
|
|
|
|
// TODO: Implement FromStr for Document
|
|
|
|
pub fn document(input: &str) -> Res<&str, Vec<Paragraph>> {
|
|
let initial_context: ContextTree<'_, '_> = ContextTree::new();
|
|
let document_context =
|
|
initial_context.with_additional_node(ContextElement::DocumentRoot(input));
|
|
let (remaining, tokens) = context_many1(&document_context, paragraph)(input)?;
|
|
let paragraphs = tokens
|
|
.into_iter()
|
|
.map(|token| match token {
|
|
Token::TextElement(_) => unreachable!(),
|
|
Token::Paragraph(paragraph) => paragraph,
|
|
})
|
|
.collect();
|
|
Ok((remaining, paragraphs))
|
|
}
|