From cfdf39d1fa26260bc30af85721cf4b17a5b7232b Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Mon, 16 Oct 2023 14:23:53 -0400 Subject: [PATCH 1/4] Significantly reduce the use of closures in the object parsers. --- src/parser/object_parser.rs | 181 ++++++++++++++---------------------- 1 file changed, 69 insertions(+), 112 deletions(-) diff --git a/src/parser/object_parser.rs b/src/parser/object_parser.rs index 0f56880..41cff19 100644 --- a/src/parser/object_parser.rs +++ b/src/parser/object_parser.rs @@ -19,6 +19,7 @@ use crate::parser::inline_babel_call::inline_babel_call; use crate::parser::inline_source_block::inline_source_block; use crate::parser::latex_fragment::latex_fragment; use crate::parser::line_break::line_break; +use crate::parser::macros::element; use crate::parser::org_macro::org_macro; use crate::parser::plain_link::plain_link; use crate::parser::radio_link::radio_link; @@ -75,56 +76,38 @@ fn standard_set_object_sans_plain_text<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, Object<'s>> { - let (remaining, object) = alt(( - map(parser_with_context!(timestamp)(context), Object::Timestamp), - map(parser_with_context!(subscript)(context), Object::Subscript), - map( - parser_with_context!(superscript)(context), - Object::Superscript, - ), - map( - parser_with_context!(statistics_cookie)(context), - Object::StatisticsCookie, - ), - map(parser_with_context!(target)(context), Object::Target), - map(parser_with_context!(line_break)(context), Object::LineBreak), - map( - parser_with_context!(inline_source_block)(context), - Object::InlineSourceBlock, - ), - map( - parser_with_context!(inline_babel_call)(context), - Object::InlineBabelCall, - ), - map(parser_with_context!(citation)(context), Object::Citation), - map( - parser_with_context!(footnote_reference)(context), - Object::FootnoteReference, - ), - map( - parser_with_context!(export_snippet)(context), - Object::ExportSnippet, - ), - map(parser_with_context!(entity)(context), Object::Entity), - map( - parser_with_context!(latex_fragment)(context), - Object::LatexFragment, - ), - map(parser_with_context!(radio_link)(context), Object::RadioLink), - map( - parser_with_context!(radio_target)(context), - Object::RadioTarget, - ), - parser_with_context!(text_markup)(context), - map( - parser_with_context!(regular_link)(context), - Object::RegularLink, - ), - map(parser_with_context!(plain_link)(context), Object::PlainLink), - map(parser_with_context!(angle_link)(context), Object::AngleLink), - map(parser_with_context!(org_macro)(context), Object::OrgMacro), - ))(input)?; - Ok((remaining, object)) + element!(timestamp, context, input, Object::Timestamp); + element!(subscript, context, input, Object::Subscript); + element!(superscript, context, input, Object::Superscript); + element!(statistics_cookie, context, input, Object::StatisticsCookie); + element!(target, context, input, Object::Target); + element!(line_break, context, input, Object::LineBreak); + element!( + inline_source_block, + context, + input, + Object::InlineSourceBlock + ); + element!(inline_babel_call, context, input, Object::InlineBabelCall); + element!(citation, context, input, Object::Citation); + element!( + footnote_reference, + context, + input, + Object::FootnoteReference + ); + element!(export_snippet, context, input, Object::ExportSnippet); + element!(entity, context, input, Object::Entity); + element!(latex_fragment, context, input, Object::LatexFragment); + element!(radio_link, context, input, Object::RadioLink); + element!(radio_target, context, input, Object::RadioTarget); + element!(text_markup, context, input); + element!(regular_link, context, input, Object::RegularLink); + element!(plain_link, context, input, Object::PlainLink); + element!(angle_link, context, input, Object::AngleLink); + element!(org_macro, context, input, Object::OrgMacro); + + Err(nom::Err::Error(CustomError::MyError(MyError("No object.")))) } #[cfg_attr( @@ -135,20 +118,12 @@ fn minimal_set_object_sans_plain_text<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, Object<'s>> { - let (remaining, object) = alt(( - map(parser_with_context!(subscript)(context), Object::Subscript), - map( - parser_with_context!(superscript)(context), - Object::Superscript, - ), - map(parser_with_context!(entity)(context), Object::Entity), - map( - parser_with_context!(latex_fragment)(context), - Object::LatexFragment, - ), - parser_with_context!(text_markup)(context), - ))(input)?; - Ok((remaining, object)) + element!(subscript, context, input, Object::Subscript); + element!(superscript, context, input, Object::Superscript); + element!(entity, context, input, Object::Entity); + element!(latex_fragment, context, input, Object::LatexFragment); + element!(text_markup, context, input); + Err(nom::Err::Error(CustomError::MyError(MyError("No object.")))) } #[cfg_attr( @@ -221,27 +196,18 @@ fn regular_link_description_set_object_sans_plain_text<'b, 'g, 'r, 's>( input: OrgSource<'s>, ) -> Res, Object<'s>> { // TODO: It can also contain another link, but only when it is a plain or angle link. It can contain square brackets, but not ]] - let (remaining, object) = alt(( - map( - parser_with_context!(export_snippet)(context), - Object::ExportSnippet, - ), - map( - parser_with_context!(statistics_cookie)(context), - Object::StatisticsCookie, - ), - map( - parser_with_context!(inline_source_block)(context), - Object::InlineSourceBlock, - ), - map( - parser_with_context!(inline_babel_call)(context), - Object::InlineBabelCall, - ), - map(parser_with_context!(org_macro)(context), Object::OrgMacro), - parser_with_context!(minimal_set_object_sans_plain_text)(context), - ))(input)?; - Ok((remaining, object)) + element!(export_snippet, context, input, Object::ExportSnippet); + element!(statistics_cookie, context, input, Object::StatisticsCookie); + element!( + inline_source_block, + context, + input, + Object::InlineSourceBlock + ); + element!(inline_babel_call, context, input, Object::InlineBabelCall); + element!(org_macro, context, input, Object::OrgMacro); + element!(minimal_set_object_sans_plain_text, context, input); + Err(nom::Err::Error(CustomError::MyError(MyError("No object.")))) } #[cfg_attr( @@ -290,33 +256,24 @@ fn table_cell_set_object_sans_plain_text<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, Object<'s>> { - let (remaining, object) = alt(( - map(parser_with_context!(citation)(context), Object::Citation), - map( - parser_with_context!(export_snippet)(context), - Object::ExportSnippet, - ), - map( - parser_with_context!(footnote_reference)(context), - Object::FootnoteReference, - ), - map(parser_with_context!(radio_link)(context), Object::RadioLink), - map( - parser_with_context!(regular_link)(context), - Object::RegularLink, - ), - map(parser_with_context!(plain_link)(context), Object::PlainLink), - map(parser_with_context!(angle_link)(context), Object::AngleLink), - map(parser_with_context!(org_macro)(context), Object::OrgMacro), - map( - parser_with_context!(radio_target)(context), - Object::RadioTarget, - ), - map(parser_with_context!(target)(context), Object::Target), - map(parser_with_context!(timestamp)(context), Object::Timestamp), - parser_with_context!(minimal_set_object_sans_plain_text)(context), - ))(input)?; - Ok((remaining, object)) + element!(citation, context, input, Object::Citation); + element!(export_snippet, context, input, Object::ExportSnippet); + element!( + footnote_reference, + context, + input, + Object::FootnoteReference + ); + element!(radio_link, context, input, Object::RadioLink); + element!(regular_link, context, input, Object::RegularLink); + element!(plain_link, context, input, Object::PlainLink); + element!(angle_link, context, input, Object::AngleLink); + element!(org_macro, context, input, Object::OrgMacro); + element!(radio_target, context, input, Object::RadioTarget); + element!(target, context, input, Object::Target); + element!(timestamp, context, input, Object::Timestamp); + element!(minimal_set_object_sans_plain_text, context, input); + Err(nom::Err::Error(CustomError::MyError(MyError("No object.")))) } #[cfg_attr( From 0020d710897493dc4666cd761580da18f93bc8f9 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Mon, 16 Oct 2023 14:36:17 -0400 Subject: [PATCH 2/4] Extend that optimization to more object parsers. --- src/parser/macros.rs | 8 ++-- src/parser/object_parser.rs | 74 ++++++++++++++++++------------------- 2 files changed, 40 insertions(+), 42 deletions(-) diff --git a/src/parser/macros.rs b/src/parser/macros.rs index f2e07ba..ea81c4e 100644 --- a/src/parser/macros.rs +++ b/src/parser/macros.rs @@ -1,6 +1,6 @@ /// Parse an element that has affiliated keywords. macro_rules! ak_element { - ($parser:ident, $affiliated_keywords:expr, $post_affiliated_keywords_input: expr, $context: expr, $input: expr, $wrapper: expr) => { + ($parser:expr, $affiliated_keywords:expr, $post_affiliated_keywords_input: expr, $context: expr, $input: expr, $wrapper: expr) => { if let Ok((remaining, ele)) = $parser( $affiliated_keywords, $post_affiliated_keywords_input, @@ -10,7 +10,7 @@ macro_rules! ak_element { return Ok((remaining, $wrapper(ele))); } }; - ($parser:ident, $affiliated_keywords:expr, $post_affiliated_keywords_input: expr, $context: expr, $input: expr) => { + ($parser:expr, $affiliated_keywords:expr, $post_affiliated_keywords_input: expr, $context: expr, $input: expr) => { if let Ok((remaining, ele)) = $parser( $affiliated_keywords, $post_affiliated_keywords_input, @@ -25,12 +25,12 @@ macro_rules! ak_element { pub(crate) use ak_element; macro_rules! element { - ($parser:ident, $context: expr, $input: expr, $wrapper: expr) => { + ($parser:expr, $context: expr, $input: expr, $wrapper: expr) => { if let Ok((remaining, ele)) = $parser($context, $input) { return Ok((remaining, $wrapper(ele))); } }; - ($parser:ident, $context: expr, $input: expr) => { + ($parser:expr, $context: expr, $input: expr) => { if let Ok((remaining, ele)) = $parser($context, $input) { return Ok((remaining, ele)); } diff --git a/src/parser/object_parser.rs b/src/parser/object_parser.rs index 41cff19..164c346 100644 --- a/src/parser/object_parser.rs +++ b/src/parser/object_parser.rs @@ -1,11 +1,7 @@ -use nom::branch::alt; -use nom::combinator::map; - use super::org_source::OrgSource; use super::plain_text::plain_text; use super::regular_link::regular_link; use super::subscript_and_superscript::detect_subscript_or_superscript; -use crate::context::parser_with_context; use crate::context::RefContext; use crate::error::CustomError; use crate::error::MyError; @@ -40,14 +36,14 @@ pub(crate) fn standard_set_object<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, Object<'s>> { - let (remaining, object) = alt(( - parser_with_context!(standard_set_object_sans_plain_text)(context), - map( - parser_with_context!(plain_text(detect_standard_set_object_sans_plain_text))(context), - Object::PlainText, - ), - ))(input)?; - Ok((remaining, object)) + element!(standard_set_object_sans_plain_text, context, input); + element!( + plain_text(detect_standard_set_object_sans_plain_text), + context, + input, + Object::PlainText + ); + Err(nom::Err::Error(CustomError::MyError(MyError("No object.")))) } #[cfg_attr( @@ -58,14 +54,14 @@ pub(crate) fn minimal_set_object<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, Object<'s>> { - let (remaining, object) = alt(( - parser_with_context!(minimal_set_object_sans_plain_text)(context), - map( - parser_with_context!(plain_text(detect_minimal_set_object_sans_plain_text))(context), - Object::PlainText, - ), - ))(input)?; - Ok((remaining, object)) + element!(minimal_set_object_sans_plain_text, context, input); + element!( + plain_text(detect_minimal_set_object_sans_plain_text), + context, + input, + Object::PlainText + ); + Err(nom::Err::Error(CustomError::MyError(MyError("No object.")))) } #[cfg_attr( @@ -175,16 +171,18 @@ pub(crate) fn regular_link_description_set_object<'b, 'g, 'r, 's>( input: OrgSource<'s>, ) -> Res, Object<'s>> { // TODO: It can also contain another link, but only when it is a plain or angle link. It can contain square brackets, but not ]] - let (remaining, object) = alt(( - parser_with_context!(regular_link_description_set_object_sans_plain_text)(context), - map( - parser_with_context!(plain_text( - detect_regular_link_description_set_object_sans_plain_text - ))(context), - Object::PlainText, - ), - ))(input)?; - Ok((remaining, object)) + element!( + regular_link_description_set_object_sans_plain_text, + context, + input + ); + element!( + plain_text(detect_regular_link_description_set_object_sans_plain_text), + context, + input, + Object::PlainText + ); + Err(nom::Err::Error(CustomError::MyError(MyError("No object.")))) } #[cfg_attr( @@ -238,14 +236,14 @@ pub(crate) fn table_cell_set_object<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, Object<'s>> { - let (remaining, object) = alt(( - parser_with_context!(table_cell_set_object_sans_plain_text)(context), - map( - parser_with_context!(plain_text(detect_table_cell_set_object_sans_plain_text))(context), - Object::PlainText, - ), - ))(input)?; - Ok((remaining, object)) + element!(table_cell_set_object_sans_plain_text, context, input); + element!( + plain_text(detect_table_cell_set_object_sans_plain_text), + context, + input, + Object::PlainText + ); + Err(nom::Err::Error(CustomError::MyError(MyError("No object.")))) } #[cfg_attr( From 7833a58461311245849589f7a1199e3090eeb0cc Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Mon, 16 Oct 2023 14:55:40 -0400 Subject: [PATCH 3/4] Apply a similar optimization to the detect element parser but also unify detection of affiliated keywords. --- src/parser/diary_sexp.rs | 17 ++++++--- src/parser/element_parser.rs | 63 ++++++++++++++++++++++++------- src/parser/fixed_width_area.rs | 17 ++++++--- src/parser/footnote_definition.rs | 19 +++++++--- src/parser/plain_list.rs | 14 ++++--- src/parser/table.rs | 17 ++++++--- 6 files changed, 108 insertions(+), 39 deletions(-) diff --git a/src/parser/diary_sexp.rs b/src/parser/diary_sexp.rs index 5f11a67..eb11817 100644 --- a/src/parser/diary_sexp.rs +++ b/src/parser/diary_sexp.rs @@ -50,12 +50,19 @@ where )) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub(crate) fn detect_diary_sexp<'b, 'g, 'r, 's>( +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context, affiliated_keywords)) +)] +pub(crate) fn detect_diary_sexp<'b, 'g, 'r, 's, AK>( + affiliated_keywords: AK, + remaining: OrgSource<'s>, context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, -) -> Res, ()> { - let (input, _) = many0(parser_with_context!(affiliated_keyword)(context))(input)?; - tuple((start_of_line, tag("%%(")))(input)?; +) -> Res, ()> +where + AK: IntoIterator>, +{ + tuple((start_of_line, tag("%%(")))(remaining)?; Ok((input, ())) } diff --git a/src/parser/element_parser.rs b/src/parser/element_parser.rs index ac4403c..c5c87a1 100644 --- a/src/parser/element_parser.rs +++ b/src/parser/element_parser.rs @@ -273,23 +273,60 @@ fn _detect_element<'b, 'g, 'r, 's>( input: OrgSource<'s>, can_be_paragraph: bool, ) -> Res, ()> { - // TODO: unify parsing of affiliated keywords like we did for the element parser. - if alt(( - parser_with_context!(detect_plain_list)(context), - parser_with_context!(detect_footnote_definition)(context), - parser_with_context!(detect_diary_sexp)(context), - detect_comment, - parser_with_context!(detect_fixed_width_area)(context), - parser_with_context!(detect_table)(context), - ))(input) - .is_ok() - { + let (post_affiliated_keywords_input, affiliated_keywords) = + many0(parser_with_context!(affiliated_keyword)(context))(input)?; + + let mut affiliated_keywords = affiliated_keywords.into_iter(); + + ak_element!( + detect_plain_list, + &mut affiliated_keywords, + post_affiliated_keywords_input, + context, + input + ); + + ak_element!( + detect_footnote_definition, + &mut affiliated_keywords, + post_affiliated_keywords_input, + context, + input + ); + + ak_element!( + detect_diary_sexp, + &mut affiliated_keywords, + post_affiliated_keywords_input, + context, + input + ); + + if let Ok((_, _)) = detect_comment(input) { return Ok((input, ())); } + + ak_element!( + detect_fixed_width_area, + &mut affiliated_keywords, + post_affiliated_keywords_input, + context, + input + ); + + ak_element!( + detect_table, + &mut affiliated_keywords, + post_affiliated_keywords_input, + context, + input + ); + if _element(context, input, can_be_paragraph).is_ok() { return Ok((input, ())); } - return Err(nom::Err::Error(CustomError::MyError(MyError( + + Err(nom::Err::Error(CustomError::MyError(MyError( "No element detected.".into(), - )))); + )))) } diff --git a/src/parser/fixed_width_area.rs b/src/parser/fixed_width_area.rs index f3efb22..2afae7d 100644 --- a/src/parser/fixed_width_area.rs +++ b/src/parser/fixed_width_area.rs @@ -89,17 +89,24 @@ fn fixed_width_area_line<'b, 'g, 'r, 's>( Ok((remaining, value)) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub(crate) fn detect_fixed_width_area<'b, 'g, 'r, 's>( +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context, affiliated_keywords)) +)] +pub(crate) fn detect_fixed_width_area<'b, 'g, 'r, 's, AK>( + affiliated_keywords: AK, + remaining: OrgSource<'s>, context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, -) -> Res, ()> { - let (input, _) = many0(parser_with_context!(affiliated_keyword)(context))(input)?; +) -> Res, ()> +where + AK: IntoIterator>, +{ tuple(( start_of_line, space0, tag(":"), alt((tag(" "), org_line_ending)), - ))(input)?; + ))(remaining)?; Ok((input, ())) } diff --git a/src/parser/footnote_definition.rs b/src/parser/footnote_definition.rs index 2f2cb1a..ea1f3c0 100644 --- a/src/parser/footnote_definition.rs +++ b/src/parser/footnote_definition.rs @@ -125,7 +125,7 @@ fn footnote_definition_end<'b, 'g, 'r, 's>( let (remaining, source) = alt(( recognize(tuple(( parser_with_context!(maybe_consume_trailing_whitespace)(context), - parser_with_context!(detect_footnote_definition)(context), + |i| detect_footnote_definition(std::iter::empty(), i, context, i), ))), recognize(tuple(( start_of_line, @@ -138,13 +138,20 @@ fn footnote_definition_end<'b, 'g, 'r, 's>( Ok((remaining, source)) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub(crate) fn detect_footnote_definition<'b, 'g, 'r, 's>( +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context, affiliated_keywords)) +)] +pub(crate) fn detect_footnote_definition<'b, 'g, 'r, 's, AK>( + affiliated_keywords: AK, + remaining: OrgSource<'s>, context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, -) -> Res, ()> { - let (input, _) = many0(parser_with_context!(affiliated_keyword)(context))(input)?; - tuple((start_of_line, tag_no_case("[fn:"), label, tag("]")))(input)?; +) -> Res, ()> +where + AK: IntoIterator>, +{ + tuple((start_of_line, tag_no_case("[fn:"), label, tag("]")))(remaining)?; Ok((input, ())) } diff --git a/src/parser/plain_list.rs b/src/parser/plain_list.rs index ef70911..f8d5ec8 100644 --- a/src/parser/plain_list.rs +++ b/src/parser/plain_list.rs @@ -53,13 +53,17 @@ use crate::types::PlainListType; #[cfg_attr( feature = "tracing", - tracing::instrument(ret, level = "debug", skip(context)) + tracing::instrument(ret, level = "debug", skip(context, affiliated_keywords)) )] -pub(crate) fn detect_plain_list<'b, 'g, 'r, 's>( +pub(crate) fn detect_plain_list<'b, 'g, 'r, 's, AK>( + affiliated_keywords: AK, + remaining: OrgSource<'s>, context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, -) -> Res, ()> { - let (input, _) = many0(parser_with_context!(affiliated_keyword)(context))(input)?; +) -> Res, ()> +where + AK: IntoIterator>, +{ if verify( tuple(( start_of_line, @@ -70,7 +74,7 @@ pub(crate) fn detect_plain_list<'b, 'g, 'r, 's>( |(_start, (indent_level, _), (_bullet_type, bull), _after_whitespace)| { !Into::<&str>::into(bull).starts_with("*") || *indent_level > 0 }, - )(input) + )(remaining) .is_ok() { return Ok((input, ())); diff --git a/src/parser/table.rs b/src/parser/table.rs index 8838756..934a30c 100644 --- a/src/parser/table.rs +++ b/src/parser/table.rs @@ -92,13 +92,20 @@ where )) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub(crate) fn detect_table<'b, 'g, 'r, 's>( +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context, affiliated_keywords)) +)] +pub(crate) fn detect_table<'b, 'g, 'r, 's, AK>( + affiliated_keywords: AK, + remaining: OrgSource<'s>, context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, -) -> Res, ()> { - let (input, _) = many0(parser_with_context!(affiliated_keyword)(context))(input)?; - tuple((start_of_line, space0, tag("|")))(input)?; +) -> Res, ()> +where + AK: IntoIterator>, +{ + tuple((start_of_line, space0, tag("|")))(remaining)?; Ok((input, ())) } From 18d0676fad218e99f1c50df4cdcfa6715152eb5e Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Mon, 16 Oct 2023 15:03:23 -0400 Subject: [PATCH 4/4] Clean up. --- src/parser/diary_sexp.rs | 9 +++------ src/parser/element_parser.rs | 2 +- src/parser/fixed_width_area.rs | 7 +++---- src/parser/footnote_definition.rs | 7 +++---- src/parser/plain_list.rs | 13 ++++++------- src/parser/table.rs | 7 +++---- 6 files changed, 19 insertions(+), 26 deletions(-) diff --git a/src/parser/diary_sexp.rs b/src/parser/diary_sexp.rs index eb11817..c58f0d3 100644 --- a/src/parser/diary_sexp.rs +++ b/src/parser/diary_sexp.rs @@ -1,15 +1,12 @@ use nom::bytes::complete::is_not; use nom::bytes::complete::tag; use nom::combinator::recognize; -use nom::multi::many0; use nom::sequence::tuple; use super::affiliated_keyword::parse_affiliated_keywords; -use super::keyword::affiliated_keyword; use super::org_source::OrgSource; use super::util::maybe_consume_trailing_whitespace_if_not_exiting; use super::util::org_line_ending; -use crate::context::parser_with_context; use crate::context::RefContext; use crate::error::Res; use crate::parser::util::get_consumed; @@ -52,12 +49,12 @@ where #[cfg_attr( feature = "tracing", - tracing::instrument(ret, level = "debug", skip(context, affiliated_keywords)) + tracing::instrument(ret, level = "debug", skip(_context, _affiliated_keywords)) )] pub(crate) fn detect_diary_sexp<'b, 'g, 'r, 's, AK>( - affiliated_keywords: AK, + _affiliated_keywords: AK, remaining: OrgSource<'s>, - context: RefContext<'b, 'g, 'r, 's>, + _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, ()> where diff --git a/src/parser/element_parser.rs b/src/parser/element_parser.rs index c5c87a1..4e0f396 100644 --- a/src/parser/element_parser.rs +++ b/src/parser/element_parser.rs @@ -1,4 +1,4 @@ -use nom::branch::alt; + use nom::multi::many0; use super::babel_call::babel_call; diff --git a/src/parser/fixed_width_area.rs b/src/parser/fixed_width_area.rs index 2afae7d..73f4d15 100644 --- a/src/parser/fixed_width_area.rs +++ b/src/parser/fixed_width_area.rs @@ -10,7 +10,6 @@ use nom::sequence::preceded; use nom::sequence::tuple; use super::affiliated_keyword::parse_affiliated_keywords; -use super::keyword::affiliated_keyword; use super::org_source::OrgSource; use super::util::maybe_consume_trailing_whitespace_if_not_exiting; use super::util::org_line_ending; @@ -91,12 +90,12 @@ fn fixed_width_area_line<'b, 'g, 'r, 's>( #[cfg_attr( feature = "tracing", - tracing::instrument(ret, level = "debug", skip(context, affiliated_keywords)) + tracing::instrument(ret, level = "debug", skip(_context, _affiliated_keywords)) )] pub(crate) fn detect_fixed_width_area<'b, 'g, 'r, 's, AK>( - affiliated_keywords: AK, + _affiliated_keywords: AK, remaining: OrgSource<'s>, - context: RefContext<'b, 'g, 'r, 's>, + _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, ()> where diff --git a/src/parser/footnote_definition.rs b/src/parser/footnote_definition.rs index ea1f3c0..cc1ca89 100644 --- a/src/parser/footnote_definition.rs +++ b/src/parser/footnote_definition.rs @@ -12,7 +12,6 @@ use nom::multi::many_till; use nom::sequence::tuple; use super::affiliated_keyword::parse_affiliated_keywords; -use super::keyword::affiliated_keyword; use super::org_source::OrgSource; use super::util::include_input; use super::util::maybe_consume_trailing_whitespace_if_not_exiting; @@ -140,12 +139,12 @@ fn footnote_definition_end<'b, 'g, 'r, 's>( #[cfg_attr( feature = "tracing", - tracing::instrument(ret, level = "debug", skip(context, affiliated_keywords)) + tracing::instrument(ret, level = "debug", skip(_context, _affiliated_keywords)) )] pub(crate) fn detect_footnote_definition<'b, 'g, 'r, 's, AK>( - affiliated_keywords: AK, + _affiliated_keywords: AK, remaining: OrgSource<'s>, - context: RefContext<'b, 'g, 'r, 's>, + _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, ()> where diff --git a/src/parser/plain_list.rs b/src/parser/plain_list.rs index f8d5ec8..0025eeb 100644 --- a/src/parser/plain_list.rs +++ b/src/parser/plain_list.rs @@ -20,7 +20,6 @@ use nom::sequence::tuple; use super::affiliated_keyword::parse_affiliated_keywords; use super::element_parser::element; -use super::keyword::affiliated_keyword; use super::object_parser::standard_set_object; use super::org_source::OrgSource; use super::util::include_input; @@ -53,10 +52,10 @@ use crate::types::PlainListType; #[cfg_attr( feature = "tracing", - tracing::instrument(ret, level = "debug", skip(context, affiliated_keywords)) + tracing::instrument(ret, level = "debug", skip(context, _affiliated_keywords)) )] pub(crate) fn detect_plain_list<'b, 'g, 'r, 's, AK>( - affiliated_keywords: AK, + _affiliated_keywords: AK, remaining: OrgSource<'s>, context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -734,7 +733,7 @@ dolar"#, let global_settings = GlobalSettings::default(); let initial_context = ContextElement::document_context(); let initial_context = Context::new(&global_settings, List::new(&initial_context)); - let result = detect_plain_list(&initial_context, input); + let result = detect_plain_list(std::iter::empty(), input, &initial_context, input); assert!(result.is_ok()); } @@ -744,7 +743,7 @@ dolar"#, let global_settings = GlobalSettings::default(); let initial_context = ContextElement::document_context(); let initial_context = Context::new(&global_settings, List::new(&initial_context)); - let result = detect_plain_list(&initial_context, input); + let result = detect_plain_list(std::iter::empty(), input, &initial_context, input); assert!(result.is_ok()); } @@ -754,7 +753,7 @@ dolar"#, let global_settings = GlobalSettings::default(); let initial_context = ContextElement::document_context(); let initial_context = Context::new(&global_settings, List::new(&initial_context)); - let result = detect_plain_list(&initial_context, input); + let result = detect_plain_list(std::iter::empty(), input, &initial_context, input); // Since there is no whitespace after the '+' this is a paragraph, not a plain list. assert!(result.is_err()); } @@ -765,7 +764,7 @@ dolar"#, let global_settings = GlobalSettings::default(); let initial_context = ContextElement::document_context(); let initial_context = Context::new(&global_settings, List::new(&initial_context)); - let result = detect_plain_list(&initial_context, input); + let result = detect_plain_list(std::iter::empty(), input, &initial_context, input); assert!(result.is_ok()); } } diff --git a/src/parser/table.rs b/src/parser/table.rs index 934a30c..e1079db 100644 --- a/src/parser/table.rs +++ b/src/parser/table.rs @@ -14,7 +14,6 @@ use nom::multi::many_till; use nom::sequence::tuple; use super::affiliated_keyword::parse_affiliated_keywords; -use super::keyword::affiliated_keyword; use super::keyword::table_formula_keyword; use super::object_parser::table_cell_set_object; use super::org_source::OrgSource; @@ -94,12 +93,12 @@ where #[cfg_attr( feature = "tracing", - tracing::instrument(ret, level = "debug", skip(context, affiliated_keywords)) + tracing::instrument(ret, level = "debug", skip(_context, _affiliated_keywords)) )] pub(crate) fn detect_table<'b, 'g, 'r, 's, AK>( - affiliated_keywords: AK, + _affiliated_keywords: AK, remaining: OrgSource<'s>, - context: RefContext<'b, 'g, 'r, 's>, + _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, ()> where