From f10efec21d6f05196457ea76d9de64a835aad437 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Mon, 16 Oct 2023 15:57:18 -0400 Subject: [PATCH] No performance change switching affiliated_key to using element macro. --- src/parser/keyword.rs | 12 +++++++----- src/parser/macros.rs | 5 +++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/parser/keyword.rs b/src/parser/keyword.rs index 2ff7566..a7ac6ae 100644 --- a/src/parser/keyword.rs +++ b/src/parser/keyword.rs @@ -27,6 +27,7 @@ use crate::context::RefContext; use crate::error::CustomError; use crate::error::MyError; use crate::error::Res; +use crate::parser::macros::element; use crate::parser::util::start_of_line; use crate::types::AffiliatedKeywords; use crate::types::Keyword; @@ -151,11 +152,12 @@ fn affiliated_key<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { - alt(( - parser_with_context!(dual_affiliated_key)(context), - parser_with_context!(plain_affiliated_key)(context), - export_keyword, - ))(input) + element!(dual_affiliated_key, context, input); + element!(plain_affiliated_key, context, input); + element!(export_keyword, input); + Err(nom::Err::Error(CustomError::MyError(MyError( + "No affiliated key.", + )))) } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] diff --git a/src/parser/macros.rs b/src/parser/macros.rs index ea81c4e..f33cf04 100644 --- a/src/parser/macros.rs +++ b/src/parser/macros.rs @@ -35,6 +35,11 @@ macro_rules! element { return Ok((remaining, ele)); } }; + ($parser:expr, $input: expr) => { + if let Ok((remaining, ele)) = $parser($input) { + return Ok((remaining, ele)); + } + }; } pub(crate) use element;