This commit is contained in:
Tom Alexander 2023-04-22 01:45:38 -04:00
parent 92ee59558b
commit 9861084afe
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
8 changed files with 16 additions and 33 deletions

View File

@ -124,8 +124,7 @@ fn zeroth_section<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s s
let without_consuming_whitespace_context =
parser_context.with_additional_node(ContextElement::ConsumeTrailingWhitespace(false));
let element_matcher = element(true);
let element_matcher = parser_with_context!(element_matcher)(&parser_context);
let element_matcher = parser_with_context!(element(true))(&parser_context);
let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context);
let (remaining, comment_and_property_drawer_element) = opt(tuple((
@ -167,8 +166,7 @@ fn section<'r, 's>(context: Context<'r, 's>, mut input: &'s str) -> Res<&'s str,
class: ExitClass::Document,
exit_matcher: &section_end,
}));
let element_matcher = element(true);
let element_matcher = parser_with_context!(element_matcher)(&parser_context);
let element_matcher = parser_with_context!(element(true))(&parser_context);
let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context);
// TODO: Match whatever a planning is.
let (mut remaining, (planning_element, property_drawer_element)) = tuple((

View File

@ -54,8 +54,7 @@ pub fn drawer<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str,
exit_matcher: &drawer_end,
}));
let element_matcher = element(true);
let element_matcher = parser_with_context!(element_matcher)(&parser_context);
let element_matcher = parser_with_context!(element(true))(&parser_context);
let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context);
let (remaining, children) = match consumed(many_till(blank_line, exit_matcher))(remaining) {
Ok((remaining, (whitespace, (_children, _exit_contents)))) => (

View File

@ -59,8 +59,7 @@ pub fn dynamic_block<'r, 's>(
Some((_ws, parameters)) => Some(parameters),
None => None,
};
let element_matcher = element(true);
let element_matcher = parser_with_context!(element_matcher)(&parser_context);
let element_matcher = parser_with_context!(element(true))(&parser_context);
let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context);
let (remaining, children) = match consumed(many_till(blank_line, exit_matcher))(remaining) {
Ok((remaining, (whitespace, (_children, _exit_contents)))) => (

View File

@ -50,8 +50,7 @@ pub fn footnote_definition<'r, 's>(
exit_matcher: &footnote_definition_end,
}));
// TODO: The problem is we are not accounting for trailing whitespace like we do in section. Maybe it would be easier if we passed down whether or not to parse trailing whitespace into the element matcher similar to how tag takes in parameters.
let element_matcher = element(true);
let element_matcher = parser_with_context!(element_matcher)(&parser_context);
let element_matcher = parser_with_context!(element(true))(&parser_context);
let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context);
let (remaining, (children, _exit_contents)) =
many_till(element_matcher, exit_matcher)(remaining)?;
@ -125,8 +124,7 @@ line footnote.";
let initial_context: ContextTree<'_, '_> = ContextTree::new();
let document_context =
initial_context.with_additional_node(ContextElement::DocumentRoot(input));
let element_matcher = element(true);
let footnote_definition_matcher = parser_with_context!(element_matcher)(&document_context);
let footnote_definition_matcher = parser_with_context!(element(true))(&document_context);
let (remaining, first_footnote_definition) =
footnote_definition_matcher(input).expect("Parse first footnote_definition");
let (remaining, second_footnote_definition) =
@ -157,8 +155,7 @@ not in the footnote.";
let initial_context: ContextTree<'_, '_> = ContextTree::new();
let document_context =
initial_context.with_additional_node(ContextElement::DocumentRoot(input));
let element_matcher = element(true);
let footnote_definition_matcher = parser_with_context!(element_matcher)(&document_context);
let footnote_definition_matcher = parser_with_context!(element(true))(&document_context);
let (remaining, first_footnote_definition) =
footnote_definition_matcher(input).expect("Parse first footnote_definition");
assert_eq!(remaining, "not in the footnote.");

View File

@ -69,8 +69,7 @@ pub fn greater_block<'r, 's>(
None => None,
};
let element_matcher = element(true);
let element_matcher = parser_with_context!(element_matcher)(&parser_context);
let element_matcher = parser_with_context!(element(true))(&parser_context);
let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context);
// Check for a completely empty block
let (remaining, children) = match consumed(many_till(blank_line, exit_matcher))(remaining) {

View File

@ -46,8 +46,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 element_matcher = element(false);
let non_paragraph_element_matcher = parser_with_context!(element_matcher)(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)))),
@ -64,16 +63,13 @@ mod tests {
use crate::parser::parser_with_context::parser_with_context;
use crate::parser::source::Source;
use super::*;
#[test]
fn two_paragraphs() {
let input = "foo bar baz\n\nlorem ipsum";
let initial_context: ContextTree<'_, '_> = ContextTree::new();
let document_context =
initial_context.with_additional_node(ContextElement::DocumentRoot(input));
let element_matcher = element(true);
let paragraph_matcher = parser_with_context!(element_matcher)(&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.");

View File

@ -1,5 +1,5 @@
macro_rules! parser_with_context {
($target:ident) => {
($target:expr) => {
move |context| move |i| $target(context, i)
};
}

View File

@ -161,10 +161,8 @@ pub fn plain_list_item<'r, 's>(
exit_matcher: &plain_list_item_end,
}));
let element_matcher = element(true);
let element_matcher = &element_matcher;
let with_consume_matcher = parser_with_context!(element_matcher)(&with_consume_context);
let without_consume_matcher = parser_with_context!(element_matcher)(&without_consume_context);
let with_consume_matcher = parser_with_context!(element(true))(&with_consume_context);
let without_consume_matcher = parser_with_context!(element(true))(&without_consume_context);
let exit_matcher = parser_with_context!(exit_matcher_parser)(&with_consume_context);
let (remaining, bull) =
verify(bullet, |bull: &str| bull != "*" || indent_level > 0)(remaining)?;
@ -372,8 +370,7 @@ mod tests {
let initial_context: ContextTree<'_, '_> = ContextTree::new();
let document_context =
initial_context.with_additional_node(ContextElement::DocumentRoot(input));
let element_matcher = element(true);
let plain_list_matcher = parser_with_context!(element_matcher)(&document_context);
let plain_list_matcher = parser_with_context!(element(true))(&document_context);
let (remaining, result) =
plain_list_matcher(input).expect("Should parse the plain list successfully.");
assert_eq!(remaining, " ipsum\n");
@ -399,8 +396,7 @@ baz"#;
let initial_context: ContextTree<'_, '_> = ContextTree::new();
let document_context =
initial_context.with_additional_node(ContextElement::DocumentRoot(input));
let element_matcher = element(true);
let plain_list_matcher = parser_with_context!(element_matcher)(&document_context);
let plain_list_matcher = parser_with_context!(element(true))(&document_context);
let (remaining, result) =
plain_list_matcher(input).expect("Should parse the plain list successfully.");
assert_eq!(remaining, "baz");
@ -431,8 +427,7 @@ dolar"#;
let initial_context: ContextTree<'_, '_> = ContextTree::new();
let document_context =
initial_context.with_additional_node(ContextElement::DocumentRoot(input));
let element_matcher = element(true);
let plain_list_matcher = parser_with_context!(element_matcher)(&document_context);
let plain_list_matcher = parser_with_context!(element(true))(&document_context);
let (remaining, result) =
plain_list_matcher(input).expect("Should parse the plain list successfully.");
assert_eq!(remaining, "dolar");