Move objects to a lower exit class.
All checks were successful
rust-test Build rust-test has succeeded
rust-build Build rust-build has succeeded

Paragraph's exit matcher which detects elements was causing the plain list parser to exit after the first item was parsed which was causing significant amounts of re-parsing.
This commit is contained in:
Tom Alexander 2023-08-24 23:34:23 -04:00
parent 33d7ae03d1
commit 02fe10fba3
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
13 changed files with 28 additions and 25 deletions

View File

@ -44,7 +44,7 @@ fn path_angle<'r, 's>(
) -> Res<OrgSource<'s>, OrgSource<'s>> {
let parser_context =
context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
class: ExitClass::Beta,
class: ExitClass::Gamma,
exit_matcher: &path_angle_end,
}));

View File

@ -90,7 +90,7 @@ fn global_prefix<'r, 's>(
depth: 0,
}))
.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
class: ExitClass::Beta,
class: ExitClass::Gamma,
exit_matcher: &global_prefix_end,
}));
let (remaining, (children, _exit_contents)) = verify(
@ -151,7 +151,7 @@ fn global_suffix<'r, 's>(
depth: 0,
}))
.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
class: ExitClass::Beta,
class: ExitClass::Gamma,
exit_matcher: &global_suffix_end,
}));
let (remaining, (children, _exit_contents)) = verify(

View File

@ -76,7 +76,7 @@ fn key_prefix<'r, 's>(
depth: 0,
}))
.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
class: ExitClass::Beta,
class: ExitClass::Gamma,
exit_matcher: &key_prefix_end,
}));
let (remaining, (children, _exit_contents)) = verify(
@ -101,7 +101,7 @@ fn key_suffix<'r, 's>(
depth: 0,
}))
.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
class: ExitClass::Beta,
class: ExitClass::Gamma,
exit_matcher: &key_suffix_end,
}));
let (remaining, (children, _exit_contents)) = verify(

View File

@ -8,6 +8,9 @@ pub enum ExitClass {
/// Elements who cede priority to alpha elements when matching.
Beta = 300,
/// Elements who cede priority to alpha and beta elements when matching.
Gamma = 4000,
}
impl std::fmt::Display for ExitClass {

View File

@ -27,7 +27,7 @@ pub fn export_snippet<'r, 's>(
let (remaining, backend_name) = backend(context, remaining)?;
let parser_context =
context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
class: ExitClass::Beta,
class: ExitClass::Gamma,
exit_matcher: &export_snippet_end,
}));
let (remaining, backend_contents) = opt(tuple((

View File

@ -49,7 +49,7 @@ fn name<'r, 's>(
) -> Res<OrgSource<'s>, OrgSource<'s>> {
let parser_context =
context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
class: ExitClass::Beta,
class: ExitClass::Gamma,
exit_matcher: &name_end,
}));
let (remaining, name) = recognize(many_till(
@ -80,7 +80,7 @@ fn header<'r, 's>(
depth: 0,
}))
.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
class: ExitClass::Beta,
class: ExitClass::Gamma,
exit_matcher: &header_end,
}));
@ -131,7 +131,7 @@ fn argument<'r, 's>(
depth: 0,
}))
.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
class: ExitClass::Beta,
class: ExitClass::Gamma,
exit_matcher: &argument_end,
}));

View File

@ -28,7 +28,7 @@ pub fn paragraph<'r, 's>(
) -> Res<OrgSource<'s>, Paragraph<'s>> {
let parser_context =
context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
class: ExitClass::Beta,
class: ExitClass::Gamma,
exit_matcher: &paragraph_end,
}));
let standard_set_object_matcher = parser_with_context!(standard_set_object)(&parser_context);

View File

@ -62,7 +62,7 @@ impl<'r, 's> ContextTree<'r, 's> {
// exit_matcher: ChainBehavior::IgnoreParent(Some(&always_fail)),
// }));
let mut current_class_filter = ExitClass::Beta;
let mut current_class_filter = ExitClass::Gamma;
for current_node in self.iter() {
let context_element = current_node.get_data();
match context_element {

View File

@ -113,7 +113,7 @@ fn path_plain<'r, 's>(
// TODO: "optionally containing parenthesis-wrapped non-whitespace non-bracket substrings up to a depth of two. The string must end with either a non-punctation non-whitespace character, a forwards slash, or a parenthesis-wrapped substring"
let parser_context =
context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
class: ExitClass::Beta,
class: ExitClass::Gamma,
exit_matcher: &path_plain_end,
}));

View File

@ -91,7 +91,7 @@ pub fn radio_target<'r, 's>(
let (remaining, _opening) = tag("<<<")(input)?;
let parser_context =
context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
class: ExitClass::Beta,
class: ExitClass::Gamma,
exit_matcher: &radio_target_end,
}));

View File

@ -162,7 +162,7 @@ fn script_with_braces<'r, 's>(
},
))
.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
class: ExitClass::Beta,
class: ExitClass::Gamma,
exit_matcher: &script_with_braces_end,
}));

View File

@ -179,7 +179,7 @@ fn _text_markup_object<'r, 's, 'x>(
let text_markup_end_specialized = text_markup_end(open.into());
let parser_context =
context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
class: ExitClass::Beta,
class: ExitClass::Gamma,
exit_matcher: &text_markup_end_specialized,
}));
@ -229,7 +229,7 @@ fn _text_markup_string<'r, 's, 'x>(
let text_markup_end_specialized = text_markup_end(open.into());
let parser_context =
context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
class: ExitClass::Beta,
class: ExitClass::Gamma,
exit_matcher: &text_markup_end_specialized,
}));
@ -338,7 +338,7 @@ fn _rematch_text_markup_object<'r, 's, 'x>(
let text_markup_end_specialized = text_markup_end(open.into());
let parser_context =
context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
class: ExitClass::Beta,
class: ExitClass::Gamma,
exit_matcher: &text_markup_end_specialized,
}));

View File

@ -67,7 +67,7 @@ fn sexp<'r, 's>(
) -> Res<OrgSource<'s>, OrgSource<'s>> {
let parser_context =
context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
class: ExitClass::Beta,
class: ExitClass::Gamma,
exit_matcher: &sexp_end,
}));
@ -99,7 +99,7 @@ fn active_timestamp<'r, 's>(
let (remaining, _date) = date(context, remaining)?;
let time_context =
context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
class: ExitClass::Beta,
class: ExitClass::Gamma,
exit_matcher: &active_time_rest_end,
}));
let (remaining, _time) =
@ -132,7 +132,7 @@ fn inactive_timestamp<'r, 's>(
let (remaining, _date) = date(context, remaining)?;
let time_context =
context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
class: ExitClass::Beta,
class: ExitClass::Gamma,
exit_matcher: &inactive_time_rest_end,
}));
let (remaining, _time) =
@ -186,12 +186,12 @@ fn active_time_range_timestamp<'r, 's>(
let (remaining, _date) = date(context, remaining)?;
let time_context =
context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
class: ExitClass::Beta,
class: ExitClass::Gamma,
exit_matcher: &active_time_rest_end,
}));
let first_time_context =
time_context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
class: ExitClass::Beta,
class: ExitClass::Gamma,
exit_matcher: &time_range_rest_end,
}));
let (remaining, _first_time) =
@ -247,12 +247,12 @@ fn inactive_time_range_timestamp<'r, 's>(
let (remaining, _date) = date(context, remaining)?;
let time_context =
context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
class: ExitClass::Beta,
class: ExitClass::Gamma,
exit_matcher: &inactive_time_rest_end,
}));
let first_time_context =
time_context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
class: ExitClass::Beta,
class: ExitClass::Gamma,
exit_matcher: &time_range_rest_end,
}));
let (remaining, _first_time) =
@ -303,7 +303,7 @@ fn dayname<'r, 's>(
) -> Res<OrgSource<'s>, OrgSource<'s>> {
let parser_context =
context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
class: ExitClass::Beta,
class: ExitClass::Gamma,
exit_matcher: &dayname_end,
}));