From 5cd34ba3a2fc27379d63ab27e81cd6c8a0fc3d75 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Mon, 9 Oct 2023 17:32:37 -0400 Subject: [PATCH] Create a new context tree when calling into confine_context. The parent exit matchers were causing an issue. --- .../greater_element/plain_list/regular_link.org | 2 ++ src/parser/radio_link.rs | 8 +++++++- src/parser/regular_link.rs | 7 ++++++- 3 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 org_mode_samples/greater_element/plain_list/regular_link.org diff --git a/org_mode_samples/greater_element/plain_list/regular_link.org b/org_mode_samples/greater_element/plain_list/regular_link.org new file mode 100644 index 00000000..53b468e2 --- /dev/null +++ b/org_mode_samples/greater_element/plain_list/regular_link.org @@ -0,0 +1,2 @@ +# This test causes problems with regular links if we do not create a new ContextTree when calling into confine_context. +- foo [[info:bar][baz]] lorem diff --git a/src/parser/radio_link.rs b/src/parser/radio_link.rs index 35a80533..efc4492f 100644 --- a/src/parser/radio_link.rs +++ b/src/parser/radio_link.rs @@ -14,9 +14,11 @@ use super::util::confine_context; use super::util::maybe_consume_object_trailing_whitespace_if_not_exiting; use super::util::text_until_exit; use crate::context::parser_with_context; +use crate::context::Context; use crate::context::ContextElement; use crate::context::ExitClass; use crate::context::ExitMatcherNode; +use crate::context::List; use crate::context::RefContext; use crate::error::CustomError; use crate::error::MyError; @@ -110,6 +112,8 @@ pub(crate) fn radio_target<'b, 'g, 'r, 's>( exit_matcher: &radio_target_end, }); let parser_context = context.with_additional_node(&parser_context); + let initial_context = ContextElement::document_context(); + let initial_context = Context::new(context.get_global_settings(), List::new(&initial_context)); let (remaining, (raw_value, children)) = consumed(map_parser( verify( @@ -117,7 +121,9 @@ pub(crate) fn radio_target<'b, 'g, 'r, 's>( |text| text.len() > 0, ), confine_context(|i| { - all_consuming(many1(parser_with_context!(minimal_set_object)(context)))(i) + all_consuming(many1(parser_with_context!(minimal_set_object)( + &initial_context, + )))(i) }), ))(remaining)?; diff --git a/src/parser/regular_link.rs b/src/parser/regular_link.rs index 6ce8c2ec..62fdff38 100644 --- a/src/parser/regular_link.rs +++ b/src/parser/regular_link.rs @@ -35,10 +35,12 @@ use super::util::get_consumed; use super::util::maybe_consume_object_trailing_whitespace_if_not_exiting; use super::util::text_until_exit; use crate::context::parser_with_context; +use crate::context::Context; use crate::context::ContextElement; use crate::context::ContextMatcher; use crate::context::ExitClass; use crate::context::ExitMatcherNode; +use crate::context::List; use crate::context::RefContext; use crate::error::CustomError; use crate::error::MyError; @@ -404,6 +406,9 @@ fn description<'b, 'g, 'r, 's>( exit_matcher: &description_end, }); let parser_context = context.with_additional_node(&parser_context); + let initial_context = ContextElement::document_context(); + let initial_context = Context::new(context.get_global_settings(), List::new(&initial_context)); + let (remaining, children) = map_parser( verify( parser_with_context!(text_until_exit)(&parser_context), @@ -412,7 +417,7 @@ fn description<'b, 'g, 'r, 's>( confine_context(|i| { all_consuming(many1(parser_with_context!( regular_link_description_set_object - )(context)))(i) + )(&initial_context)))(i) }), )(input)?;