Moving towards unifying into a single parameterized element matcher.

This is to give paragraph priority over keyword in parsing so that affiliated keywords for paragraphs will be parsed as such.
This commit is contained in:
Tom Alexander
2023-04-22 00:55:31 -04:00
parent fef5841713
commit 4ac6d89311
8 changed files with 81 additions and 99 deletions

View File

@@ -16,7 +16,6 @@ use crate::parser::util::exit_matcher_parser;
use crate::parser::util::start_of_line;
use super::element_parser::non_paragraph_element;
use super::lesser_element::Paragraph;
use super::util::blank_line;
use super::util::get_consumed;
@@ -46,7 +45,7 @@ pub fn paragraph<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s st
#[tracing::instrument(ret, level = "debug")]
fn paragraph_end<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, &'s str> {
let non_paragraph_element_matcher = parser_with_context!(non_paragraph_element)(context);
let non_paragraph_element_matcher = parser_with_context!(element(false))(context);
let start_of_line_matcher = parser_with_context!(start_of_line)(&context);
alt((
recognize(tuple((start_of_line_matcher, many1(blank_line)))),
@@ -57,7 +56,7 @@ fn paragraph_end<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s st
#[cfg(test)]
mod tests {
use crate::parser::element_parser::paragraph_element;
use crate::parser::element_parser::element;
use crate::parser::parser_context::ContextElement;
use crate::parser::parser_context::ContextTree;
use crate::parser::parser_with_context::parser_with_context;
@@ -71,7 +70,7 @@ mod tests {
let initial_context: ContextTree<'_, '_> = ContextTree::new();
let document_context =
initial_context.with_additional_node(ContextElement::DocumentRoot(input));
let paragraph_matcher = parser_with_context!(paragraph_element)(&document_context);
let paragraph_matcher = parser_with_context!(element(true))(&document_context);
let (remaining, first_paragraph) = paragraph_matcher(input).expect("Parse first paragraph");
let (remaining, second_paragraph) =
paragraph_matcher(remaining).expect("Parse second paragraph.");