Remove context from functions that no longer need it.

This commit is contained in:
Tom Alexander 2023-10-18 18:28:24 -04:00
parent ba72cc1b29
commit 49d1cef7ae
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
3 changed files with 15 additions and 35 deletions

View File

@ -26,7 +26,6 @@ use crate::context::Context;
use crate::context::ContextElement; use crate::context::ContextElement;
use crate::context::GlobalSettings; use crate::context::GlobalSettings;
use crate::context::List; use crate::context::List;
use crate::context::RefContext;
use crate::error::Res; use crate::error::Res;
use crate::types::AffiliatedKeywordValue; use crate::types::AffiliatedKeywordValue;
use crate::types::AffiliatedKeywords; use crate::types::AffiliatedKeywords;
@ -36,15 +35,14 @@ use crate::types::Keyword;
feature = "tracing", feature = "tracing",
tracing::instrument(ret, level = "debug", skip(context)) tracing::instrument(ret, level = "debug", skip(context))
)] )]
pub(crate) fn affiliated_keywords<'b, 'g, 'r, 's>( pub(crate) fn affiliated_keywords<'s>(
context: RefContext<'b, 'g, 'r, 's>,
input: OrgSource<'s>, input: OrgSource<'s>,
) -> Res<OrgSource<'s>, Vec<Keyword<'s>>> { ) -> Res<OrgSource<'s>, Vec<Keyword<'s>>> {
let mut ret = Vec::new(); let mut ret = Vec::new();
let mut remaining = input; let mut remaining = input;
loop { loop {
let result = affiliated_keyword(context, remaining); let result = affiliated_keyword(remaining);
match result { match result {
Ok((remain, kw)) => { Ok((remain, kw)) => {
remaining = remain; remaining = remain;
@ -68,8 +66,8 @@ where
{ {
let mut ret = BTreeMap::new(); let mut ret = BTreeMap::new();
for kw in input { for kw in input {
let translated_name = translate_name(global_settings, kw.key); let translated_name = translate_name(kw.key);
let keyword_type = identify_keyword_type(global_settings, translated_name.as_str()); let keyword_type = identify_keyword_type(translated_name.as_str());
match keyword_type { match keyword_type {
AffiliatedKeywordType::SingleString => { AffiliatedKeywordType::SingleString => {
ret.insert( ret.insert(
@ -154,7 +152,7 @@ where
AffiliatedKeywords { keywords: ret } 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 let name_until_optval = name
.split_once('[') .split_once('[')
.map(|(before, _after)| before) .map(|(before, _after)| before)
@ -174,10 +172,7 @@ enum AffiliatedKeywordType {
ObjectTree, ObjectTree,
} }
fn identify_keyword_type<'g, 's>( fn identify_keyword_type<'g, 's>(name: &'s str) -> AffiliatedKeywordType {
global_settings: &'g GlobalSettings<'g, 's>,
name: &'s str,
) -> AffiliatedKeywordType {
let is_multiple = ["CAPTION", "HEADER"] let is_multiple = ["CAPTION", "HEADER"]
.into_iter() .into_iter()
.any(|candidate| name.eq_ignore_ascii_case(candidate)) .any(|candidate| name.eq_ignore_ascii_case(candidate))

View File

@ -59,8 +59,7 @@ fn _element<'b, 'g, 'r, 's>(
) -> Res<OrgSource<'s>, Element<'s>> { ) -> Res<OrgSource<'s>, Element<'s>> {
#[cfg(feature = "event_count")] #[cfg(feature = "event_count")]
record_event(EventType::ElementStart, input); record_event(EventType::ElementStart, input);
let (post_affiliated_keywords_input, affiliated_keywords) = let (post_affiliated_keywords_input, affiliated_keywords) = affiliated_keywords(input)?;
affiliated_keywords(context, input)?;
let mut affiliated_keywords = affiliated_keywords.into_iter(); let mut affiliated_keywords = affiliated_keywords.into_iter();
@ -277,8 +276,7 @@ fn _detect_element<'b, 'g, 'r, 's>(
input: OrgSource<'s>, input: OrgSource<'s>,
can_be_paragraph: bool, can_be_paragraph: bool,
) -> Res<OrgSource<'s>, ()> { ) -> Res<OrgSource<'s>, ()> {
let (post_affiliated_keywords_input, affiliated_keywords) = let (post_affiliated_keywords_input, affiliated_keywords) = affiliated_keywords(input)?;
affiliated_keywords(context, input)?;
let mut affiliated_keywords = affiliated_keywords.into_iter(); let mut affiliated_keywords = affiliated_keywords.into_iter();

View File

@ -21,7 +21,6 @@ use super::org_source::OrgSource;
use super::util::get_consumed; use super::util::get_consumed;
use super::util::maybe_consume_trailing_whitespace_if_not_exiting; use super::util::maybe_consume_trailing_whitespace_if_not_exiting;
use super::util::org_line_ending; 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_AFFILIATED_KEYWORDS;
use crate::context::constants::ORG_ELEMENT_DUAL_KEYWORDS; use crate::context::constants::ORG_ELEMENT_DUAL_KEYWORDS;
use crate::context::RefContext; use crate::context::RefContext;
@ -100,11 +99,8 @@ where
} }
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
pub(crate) fn affiliated_keyword<'b, 'g, 'r, 's>( pub(crate) fn affiliated_keyword<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, Keyword<'s>> {
context: RefContext<'b, 'g, 'r, 's>, filtered_keyword(affiliated_key)(input)
input: OrgSource<'s>,
) -> Res<OrgSource<'s>, Keyword<'s>> {
filtered_keyword(bind_context!(affiliated_key, context))(input)
} }
#[cfg_attr( #[cfg_attr(
@ -139,21 +135,15 @@ fn regular_keyword_key<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource
} }
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
fn affiliated_key<'b, 'g, 'r, 's>( fn affiliated_key<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>> {
context: RefContext<'b, 'g, 'r, 's>, element!(dual_affiliated_key, input);
input: OrgSource<'s>, element!(plain_affiliated_key, input);
) -> Res<OrgSource<'s>, OrgSource<'s>> {
element!(dual_affiliated_key, context, input);
element!(plain_affiliated_key, context, input);
element!(export_keyword, input); element!(export_keyword, input);
Err(nom::Err::Error(CustomError::Static("No affiliated key."))) Err(nom::Err::Error(CustomError::Static("No affiliated key.")))
} }
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
fn plain_affiliated_key<'b, 'g, 'r, 's>( fn plain_affiliated_key<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>> {
context: RefContext<'b, 'g, 'r, 's>,
input: OrgSource<'s>,
) -> Res<OrgSource<'s>, OrgSource<'s>> {
for keyword in ORG_ELEMENT_AFFILIATED_KEYWORDS { for keyword in ORG_ELEMENT_AFFILIATED_KEYWORDS {
let result = map( let result = map(
tuple((tag_no_case::<_, _, CustomError>(keyword), peek(tag(":")))), 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"))] #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
fn dual_affiliated_key<'b, 'g, 'r, 's>( fn dual_affiliated_key<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>> {
context: RefContext<'b, 'g, 'r, 's>,
input: OrgSource<'s>,
) -> Res<OrgSource<'s>, OrgSource<'s>> {
for keyword in ORG_ELEMENT_DUAL_KEYWORDS { for keyword in ORG_ELEMENT_DUAL_KEYWORDS {
let result = recognize(tuple(( let result = recognize(tuple((
tag_no_case::<_, _, CustomError>(keyword), tag_no_case::<_, _, CustomError>(keyword),