From 49d1cef7aef9427eb96b6366c2c623bd29eae480 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Wed, 18 Oct 2023 18:28:24 -0400 Subject: [PATCH] Remove context from functions that no longer need it. --- src/parser/affiliated_keyword.rs | 17 ++++++----------- src/parser/element_parser.rs | 6 ++---- src/parser/keyword.rs | 27 +++++++-------------------- 3 files changed, 15 insertions(+), 35 deletions(-) diff --git a/src/parser/affiliated_keyword.rs b/src/parser/affiliated_keyword.rs index 6099588..a684ce4 100644 --- a/src/parser/affiliated_keyword.rs +++ b/src/parser/affiliated_keyword.rs @@ -26,7 +26,6 @@ use crate::context::Context; use crate::context::ContextElement; use crate::context::GlobalSettings; use crate::context::List; -use crate::context::RefContext; use crate::error::Res; use crate::types::AffiliatedKeywordValue; use crate::types::AffiliatedKeywords; @@ -36,15 +35,14 @@ use crate::types::Keyword; feature = "tracing", tracing::instrument(ret, level = "debug", skip(context)) )] -pub(crate) fn affiliated_keywords<'b, 'g, 'r, 's>( - context: RefContext<'b, 'g, 'r, 's>, +pub(crate) fn affiliated_keywords<'s>( input: OrgSource<'s>, ) -> Res, Vec>> { let mut ret = Vec::new(); let mut remaining = input; loop { - let result = affiliated_keyword(context, remaining); + let result = affiliated_keyword(remaining); match result { Ok((remain, kw)) => { remaining = remain; @@ -68,8 +66,8 @@ where { let mut ret = BTreeMap::new(); for kw in input { - let translated_name = translate_name(global_settings, kw.key); - let keyword_type = identify_keyword_type(global_settings, translated_name.as_str()); + let translated_name = translate_name(kw.key); + let keyword_type = identify_keyword_type(translated_name.as_str()); match keyword_type { AffiliatedKeywordType::SingleString => { ret.insert( @@ -154,7 +152,7 @@ where AffiliatedKeywords { keywords: ret } } -fn translate_name<'g, 's>(global_settings: &'g GlobalSettings<'g, 's>, name: &'s str) -> String { +fn translate_name<'g, 's>(name: &'s str) -> String { let name_until_optval = name .split_once('[') .map(|(before, _after)| before) @@ -174,10 +172,7 @@ enum AffiliatedKeywordType { ObjectTree, } -fn identify_keyword_type<'g, 's>( - global_settings: &'g GlobalSettings<'g, 's>, - name: &'s str, -) -> AffiliatedKeywordType { +fn identify_keyword_type<'g, 's>(name: &'s str) -> AffiliatedKeywordType { let is_multiple = ["CAPTION", "HEADER"] .into_iter() .any(|candidate| name.eq_ignore_ascii_case(candidate)) diff --git a/src/parser/element_parser.rs b/src/parser/element_parser.rs index 774abd8..6d5fca8 100644 --- a/src/parser/element_parser.rs +++ b/src/parser/element_parser.rs @@ -59,8 +59,7 @@ fn _element<'b, 'g, 'r, 's>( ) -> Res, Element<'s>> { #[cfg(feature = "event_count")] record_event(EventType::ElementStart, input); - let (post_affiliated_keywords_input, affiliated_keywords) = - affiliated_keywords(context, input)?; + let (post_affiliated_keywords_input, affiliated_keywords) = affiliated_keywords(input)?; let mut affiliated_keywords = affiliated_keywords.into_iter(); @@ -277,8 +276,7 @@ fn _detect_element<'b, 'g, 'r, 's>( input: OrgSource<'s>, can_be_paragraph: bool, ) -> Res, ()> { - let (post_affiliated_keywords_input, affiliated_keywords) = - affiliated_keywords(context, input)?; + let (post_affiliated_keywords_input, affiliated_keywords) = affiliated_keywords(input)?; let mut affiliated_keywords = affiliated_keywords.into_iter(); diff --git a/src/parser/keyword.rs b/src/parser/keyword.rs index 63c608d..f6cca6c 100644 --- a/src/parser/keyword.rs +++ b/src/parser/keyword.rs @@ -21,7 +21,6 @@ use super::org_source::OrgSource; use super::util::get_consumed; use super::util::maybe_consume_trailing_whitespace_if_not_exiting; use super::util::org_line_ending; -use crate::context::bind_context; use crate::context::constants::ORG_ELEMENT_AFFILIATED_KEYWORDS; use crate::context::constants::ORG_ELEMENT_DUAL_KEYWORDS; use crate::context::RefContext; @@ -100,11 +99,8 @@ where } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub(crate) fn affiliated_keyword<'b, 'g, 'r, 's>( - context: RefContext<'b, 'g, 'r, 's>, - input: OrgSource<'s>, -) -> Res, Keyword<'s>> { - filtered_keyword(bind_context!(affiliated_key, context))(input) +pub(crate) fn affiliated_keyword<'s>(input: OrgSource<'s>) -> Res, Keyword<'s>> { + filtered_keyword(affiliated_key)(input) } #[cfg_attr( @@ -139,21 +135,15 @@ fn regular_keyword_key<'s>(input: OrgSource<'s>) -> Res, OrgSource } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn affiliated_key<'b, 'g, 'r, 's>( - context: RefContext<'b, 'g, 'r, 's>, - input: OrgSource<'s>, -) -> Res, OrgSource<'s>> { - element!(dual_affiliated_key, context, input); - element!(plain_affiliated_key, context, input); +fn affiliated_key<'s>(input: OrgSource<'s>) -> Res, OrgSource<'s>> { + element!(dual_affiliated_key, input); + element!(plain_affiliated_key, input); element!(export_keyword, input); Err(nom::Err::Error(CustomError::Static("No affiliated key."))) } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn plain_affiliated_key<'b, 'g, 'r, 's>( - context: RefContext<'b, 'g, 'r, 's>, - input: OrgSource<'s>, -) -> Res, OrgSource<'s>> { +fn plain_affiliated_key<'s>(input: OrgSource<'s>) -> Res, OrgSource<'s>> { for keyword in ORG_ELEMENT_AFFILIATED_KEYWORDS { let result = map( tuple((tag_no_case::<_, _, CustomError>(keyword), peek(tag(":")))), @@ -168,10 +158,7 @@ fn plain_affiliated_key<'b, 'g, 'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn dual_affiliated_key<'b, 'g, 'r, 's>( - context: RefContext<'b, 'g, 'r, 's>, - input: OrgSource<'s>, -) -> Res, OrgSource<'s>> { +fn dual_affiliated_key<'s>(input: OrgSource<'s>) -> Res, OrgSource<'s>> { for keyword in ORG_ELEMENT_DUAL_KEYWORDS { let result = recognize(tuple(( tag_no_case::<_, _, CustomError>(keyword),