diff --git a/src/parser/document.rs b/src/parser/document.rs index 26c844a..6e202f5 100644 --- a/src/parser/document.rs +++ b/src/parser/document.rs @@ -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: §ion_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(( diff --git a/src/parser/drawer.rs b/src/parser/drawer.rs index d0c7d7b..9c93a94 100644 --- a/src/parser/drawer.rs +++ b/src/parser/drawer.rs @@ -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)))) => ( diff --git a/src/parser/dynamic_block.rs b/src/parser/dynamic_block.rs index 005cd0d..d523920 100644 --- a/src/parser/dynamic_block.rs +++ b/src/parser/dynamic_block.rs @@ -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)))) => ( diff --git a/src/parser/footnote_definition.rs b/src/parser/footnote_definition.rs index 89704b5..00f1077 100644 --- a/src/parser/footnote_definition.rs +++ b/src/parser/footnote_definition.rs @@ -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."); diff --git a/src/parser/greater_block.rs b/src/parser/greater_block.rs index 1878915..8ca1fe1 100644 --- a/src/parser/greater_block.rs +++ b/src/parser/greater_block.rs @@ -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) { diff --git a/src/parser/paragraph.rs b/src/parser/paragraph.rs index 55947ed..ba9c557 100644 --- a/src/parser/paragraph.rs +++ b/src/parser/paragraph.rs @@ -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."); diff --git a/src/parser/parser_with_context.rs b/src/parser/parser_with_context.rs index e5d6086..6705d47 100644 --- a/src/parser/parser_with_context.rs +++ b/src/parser/parser_with_context.rs @@ -1,5 +1,5 @@ macro_rules! parser_with_context { - ($target:ident) => { + ($target:expr) => { move |context| move |i| $target(context, i) }; } diff --git a/src/parser/plain_list.rs b/src/parser/plain_list.rs index 5c15235..d84b04a 100644 --- a/src/parser/plain_list.rs +++ b/src/parser/plain_list.rs @@ -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");