Add a DocumentRoot context element storing the original full document.
This might be used for look-behind instead of storing previous element nodes in the context tree.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
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;
|
||||
@@ -14,7 +15,9 @@ type UnboundMatcher<'r, 's, I, O, E> = dyn Fn(Context<'r, 's>, I) -> IResult<I,
|
||||
|
||||
pub fn document(input: &str) -> Res<&str, Vec<Paragraph>> {
|
||||
let initial_context: ContextTree<'_, '_> = ContextTree::new();
|
||||
let (remaining, tokens) = context_many1(&initial_context, paragraph)(input)?;
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user