From e111b8b9b87fca73537dc961e58984cce57d3015 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Wed, 18 Oct 2023 12:36:06 -0400 Subject: [PATCH] Performance optimization. --- src/parser/bullshitium.rs | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/parser/bullshitium.rs b/src/parser/bullshitium.rs index ca6dda9..27151c0 100644 --- a/src/parser/bullshitium.rs +++ b/src/parser/bullshitium.rs @@ -12,7 +12,9 @@ use super::util::start_of_line; use super::OrgSource; use crate::context::bind_context; use crate::context::RefContext; +use crate::error::CustomError; use crate::error::Res; +use crate::parser::macros::element; use crate::types::AffiliatedKeywords; use crate::types::Object; use crate::types::Paragraph; @@ -40,8 +42,9 @@ pub(crate) fn detect_bullshitium<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, ()> { - bullshitium(context, input)?; - Ok((input, ())) + element!(detect_broken_end, context, input); + element!(detect_broken_dynamic_block, context, input); + Err(nom::Err::Error(CustomError::Static("No bullshitium."))) } #[cfg_attr( @@ -88,6 +91,21 @@ pub(crate) fn broken_end<'b, 'g, 'r, 's>( } } +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] +pub(crate) fn detect_broken_end<'b, 'g, 'r, 's>( + _context: RefContext<'b, 'g, 'r, 's>, + input: OrgSource<'s>, +) -> Res, ()> { + start_of_line(input)?; + let (remaining, _) = space0(input)?; + let (remaining, _) = tag_no_case(":end:")(remaining)?; + let (_remaining, _) = tuple((space0, org_line_ending))(remaining)?; + Ok((input, ())) +} + #[cfg_attr( feature = "tracing", tracing::instrument(ret, level = "debug", skip(context)) @@ -131,3 +149,17 @@ pub(crate) fn broken_dynamic_block<'b, 'g, 'r, 's>( )) } } + +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] +pub(crate) fn detect_broken_dynamic_block<'b, 'g, 'r, 's>( + _context: RefContext<'b, 'g, 'r, 's>, + input: OrgSource<'s>, +) -> Res, ()> { + start_of_line(input)?; + let (remaining, _) = space0(input)?; + let (_remaining, _) = tag_no_case("#+BEGIN:")(remaining)?; + Ok((input, ())) +}