diff --git a/.gitignore b/.gitignore index 96ef6c0..8d2488e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /target Cargo.lock +TODO.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 0000000..53b468e --- /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/org_mode_samples/object/text_markup/double_star.org b/org_mode_samples/object/text_markup/double_star.org index c758a3d..3cc032d 100644 --- a/org_mode_samples/object/text_markup/double_star.org +++ b/org_mode_samples/object/text_markup/double_star.org @@ -1 +1,3 @@ +**foo** + foo ** bar ** baz diff --git a/org_mode_samples/object/text_markup/double_underscore.org b/org_mode_samples/object/text_markup/double_underscore.org new file mode 100644 index 0000000..2664fa1 --- /dev/null +++ b/org_mode_samples/object/text_markup/double_underscore.org @@ -0,0 +1 @@ +__foo_bar_baz__ diff --git a/src/compare/compare_field.rs b/src/compare/compare_field.rs index e0f4413..8ee4557 100644 --- a/src/compare/compare_field.rs +++ b/src/compare/compare_field.rs @@ -1,36 +1,46 @@ use std::fmt::Debug; +use super::diff::artificial_diff_scope; +use super::diff::compare_ast_node; +use super::diff::DiffEntry; use super::diff::DiffStatus; use super::sexp::unquote; use super::sexp::Token; use super::util::get_property; use super::util::get_property_quoted_string; use super::util::get_property_unquoted_atom; +use crate::types::AstNode; #[derive(Debug)] pub(crate) enum EmacsField<'s> { Required(&'s str), - #[allow(dead_code)] Optional(&'s str), } +#[derive(Debug)] +pub(crate) enum ComparePropertiesResult<'b, 's> { + NoChange, + /// Return when you want the status for "this" node to change (as opposed to collecting child status). + SelfChange(DiffStatus, Option), + DiffEntry(DiffEntry<'b, 's>), +} + /// Do no comparison. /// /// This is for when you want to acknowledge that a field exists in the emacs token, but you do not have any validation for it when using the compare_properties!() macro. Ideally, this should be kept to a minimum since this represents untested values. -#[allow(dead_code)] pub(crate) fn compare_noop<'b, 's, 'x, R, RG>( + _source: &'s str, _emacs: &'b Token<'s>, _rust_node: R, _emacs_field: &'x str, _rust_value_getter: RG, -) -> Result)>, Box> { - Ok(None) +) -> Result, Box> { + Ok(ComparePropertiesResult::NoChange) } /// Do no comparison. /// /// This is for when you want to acknowledge that a field exists in the emacs token, but you do not have any validation for it when using the compare_properties!() macro. Ideally, this should be kept to a minimum since this represents untested values. -#[allow(dead_code)] pub(crate) fn compare_identity() -> () { () } @@ -39,11 +49,12 @@ pub(crate) fn compare_identity() -> () { /// /// This is usually used for fields which, in my testing, are always nil. Using this compare function instead of simply doing a compare_noop will enable us to be alerted when we finally come across an org-mode document that has a value other than nil for the property. pub(crate) fn compare_property_always_nil<'b, 's, 'x, R, RG>( + _source: &'s str, emacs: &'b Token<'s>, _rust_node: R, emacs_field: &'x str, _rust_value_getter: RG, -) -> Result)>, Box> { +) -> Result, Box> { let value = get_property(emacs, emacs_field)?; if value.is_some() { let this_status = DiffStatus::Bad; @@ -51,9 +62,9 @@ pub(crate) fn compare_property_always_nil<'b, 's, 'x, R, RG>( "{} was expected to always be nil: {:?}", emacs_field, value )); - Ok(Some((this_status, message))) + Ok(ComparePropertiesResult::SelfChange(this_status, message)) } else { - Ok(None) + Ok(ComparePropertiesResult::NoChange) } } @@ -65,11 +76,12 @@ pub(crate) fn compare_property_quoted_string< RV: AsRef + std::fmt::Debug, RG: Fn(R) -> Option, >( + _source: &'s str, emacs: &'b Token<'s>, rust_node: R, emacs_field: &'x str, rust_value_getter: RG, -) -> Result)>, Box> { +) -> Result, Box> { let value = get_property_quoted_string(emacs, emacs_field)?; let rust_value = rust_value_getter(rust_node); if rust_value.as_ref().map(|s| s.as_ref()) != value.as_ref().map(String::as_str) { @@ -78,18 +90,19 @@ pub(crate) fn compare_property_quoted_string< "{} mismatch (emacs != rust) {:?} != {:?}", emacs_field, value, rust_value )); - Ok(Some((this_status, message))) + Ok(ComparePropertiesResult::SelfChange(this_status, message)) } else { - Ok(None) + Ok(ComparePropertiesResult::NoChange) } } pub(crate) fn compare_property_unquoted_atom<'b, 's, 'x, R, RG: Fn(R) -> Option<&'s str>>( + _source: &'s str, emacs: &'b Token<'s>, rust_node: R, emacs_field: &'x str, rust_value_getter: RG, -) -> Result)>, Box> { +) -> Result, Box> { let value = get_property_unquoted_atom(emacs, emacs_field)?; let rust_value = rust_value_getter(rust_node); if rust_value != value { @@ -98,9 +111,9 @@ pub(crate) fn compare_property_unquoted_atom<'b, 's, 'x, R, RG: Fn(R) -> Option< "{} mismatch (emacs != rust) {:?} != {:?}", emacs_field, value, rust_value )); - Ok(Some((this_status, message))) + Ok(ComparePropertiesResult::SelfChange(this_status, message)) } else { - Ok(None) + Ok(ComparePropertiesResult::NoChange) } } @@ -113,11 +126,12 @@ pub(crate) fn compare_property_list_of_quoted_string< RI: Iterator, RG: Fn(R) -> Option, >( + _source: &'s str, emacs: &'b Token<'s>, rust_node: R, emacs_field: &'x str, rust_value_getter: RG, -) -> Result)>, Box> { +) -> Result, Box> { let value = get_property(emacs, emacs_field)? .map(Token::as_list) .map_or(Ok(None), |r| r.map(Some))?; @@ -132,7 +146,7 @@ pub(crate) fn compare_property_list_of_quoted_string< "{} mismatch (emacs != rust) {:?} != {:?}", emacs_field, value, rust_value )); - return Ok(Some((this_status, message))); + return Ok(ComparePropertiesResult::SelfChange(this_status, message)); } (Some(el), Some(rl)) if el.len() != rl.len() => { let this_status = DiffStatus::Bad; @@ -140,7 +154,7 @@ pub(crate) fn compare_property_list_of_quoted_string< "{} mismatch (emacs != rust) {:?} != {:?}", emacs_field, value, rust_value )); - return Ok(Some((this_status, message))); + return Ok(ComparePropertiesResult::SelfChange(this_status, message)); } (Some(el), Some(rl)) => { for (e, r) in el.iter().zip(rl) { @@ -152,20 +166,21 @@ pub(crate) fn compare_property_list_of_quoted_string< "{} mismatch (emacs != rust) {:?} != {:?}. Full list: {:?} != {:?}", emacs_field, e, r, value, rust_value )); - return Ok(Some((this_status, message))); + return Ok(ComparePropertiesResult::SelfChange(this_status, message)); } } } } - Ok(None) + Ok(ComparePropertiesResult::NoChange) } pub(crate) fn compare_property_boolean<'b, 's, 'x, R, RG: Fn(R) -> bool>( + _source: &'s str, emacs: &'b Token<'s>, rust_node: R, emacs_field: &'x str, rust_value_getter: RG, -) -> Result)>, Box> { +) -> Result, Box> { // get_property already converts nil to None. let value = get_property(emacs, emacs_field)?.is_some(); let rust_value = rust_value_getter(rust_node); @@ -175,8 +190,62 @@ pub(crate) fn compare_property_boolean<'b, 's, 'x, R, RG: Fn(R) -> bool>( "{} mismatch (emacs != rust) {:?} != {:?}", emacs_field, value, rust_value )); - Ok(Some((this_status, message))) + Ok(ComparePropertiesResult::SelfChange(this_status, message)) } else { - Ok(None) + Ok(ComparePropertiesResult::NoChange) } } + +pub(crate) fn compare_property_list_of_ast_nodes< + 'b, + 's, + 'x: 'b + 's, + R, + RV: std::fmt::Debug, + RI: Iterator, + RG: Fn(R) -> Option, +>( + source: &'s str, + emacs: &'b Token<'s>, + rust_node: R, + emacs_field: &'x str, + rust_value_getter: RG, +) -> Result, Box> +where + AstNode<'b, 's>: From, +{ + let value = get_property(emacs, emacs_field)? + .map(Token::as_list) + .map_or(Ok(None), |r| r.map(Some))?; + let rust_value = rust_value_getter(rust_node); + // TODO: Seems we are needlessly coverting to a vec here. + let rust_value: Option> = rust_value.map(|it| it.collect()); + match (value, rust_value) { + (None, None) => {} + (None, rv @ Some(_)) | (Some(_), rv @ None) => { + let this_status = DiffStatus::Bad; + let message = Some(format!( + "{} mismatch (emacs != rust) {:?} != {:?}", + emacs_field, value, rv + )); + return Ok(ComparePropertiesResult::SelfChange(this_status, message)); + } + (Some(el), Some(rl)) if el.len() != rl.len() => { + let this_status = DiffStatus::Bad; + let message = Some(format!( + "{} mismatch (emacs != rust) {:?} != {:?}", + emacs_field, el, rl + )); + return Ok(ComparePropertiesResult::SelfChange(this_status, message)); + } + (Some(el), Some(rl)) => { + let mut child_status: Vec> = Vec::with_capacity(rl.len()); + for (e, r) in el.iter().zip(rl) { + child_status.push(compare_ast_node(source, e, r.into())?); + } + let diff_scope = artificial_diff_scope(emacs_field, child_status)?; + return Ok(ComparePropertiesResult::DiffEntry(diff_scope)); + } + } + Ok(ComparePropertiesResult::NoChange) +} diff --git a/src/compare/diff.rs b/src/compare/diff.rs index 9a0fe22..7eeb4d3 100644 --- a/src/compare/diff.rs +++ b/src/compare/diff.rs @@ -8,6 +8,7 @@ use super::compare_field::compare_identity; use super::compare_field::compare_noop; use super::compare_field::compare_property_always_nil; use super::compare_field::compare_property_boolean; +use super::compare_field::compare_property_list_of_ast_nodes; use super::compare_field::compare_property_list_of_quoted_string; use super::compare_field::compare_property_quoted_string; use super::compare_field::compare_property_unquoted_atom; @@ -23,6 +24,7 @@ use super::util::get_property_boolean; use super::util::get_property_numeric; use super::util::get_property_quoted_string; use super::util::get_property_unquoted_atom; +use crate::compare::compare_field::ComparePropertiesResult; use crate::compare::compare_field::EmacsField; use crate::compare::macros::compare_properties; use crate::types::AngleLink; @@ -328,8 +330,8 @@ impl<'b, 's> DiffLayer<'b, 's> { } } -fn artificial_diff_scope<'b, 's>( - name: &'static str, +pub(crate) fn artificial_diff_scope<'b, 's>( + name: &'s str, children: Vec>, ) -> Result, Box> { Ok(DiffLayer { @@ -2598,16 +2600,22 @@ fn compare_bold<'b, 's>( &mut message, )?; - if let Some((new_status, new_message)) = compare_properties!(emacs)? { - this_status = new_status; - message = new_message; + for diff in compare_properties!(emacs) { + match diff { + ComparePropertiesResult::NoChange => {} + ComparePropertiesResult::SelfChange(new_status, new_message) => { + this_status = new_status; + message = new_message + } + ComparePropertiesResult::DiffEntry(diff_entry) => child_status.push(diff_entry), + } } Ok(DiffResult { status: this_status, name: rust.get_elisp_name(), message, - children: Vec::new(), + children: child_status, rust_source: rust.get_source(), emacs_token: emacs, } @@ -2632,16 +2640,22 @@ fn compare_italic<'b, 's>( &mut message, )?; - if let Some((new_status, new_message)) = compare_properties!(emacs)? { - this_status = new_status; - message = new_message; + for diff in compare_properties!(emacs) { + match diff { + ComparePropertiesResult::NoChange => {} + ComparePropertiesResult::SelfChange(new_status, new_message) => { + this_status = new_status; + message = new_message + } + ComparePropertiesResult::DiffEntry(diff_entry) => child_status.push(diff_entry), + } } Ok(DiffResult { status: this_status, name: rust.get_elisp_name(), message, - children: Vec::new(), + children: child_status, rust_source: rust.get_source(), emacs_token: emacs, } @@ -2666,16 +2680,22 @@ fn compare_underline<'b, 's>( &mut message, )?; - if let Some((new_status, new_message)) = compare_properties!(emacs)? { - this_status = new_status; - message = new_message; + for diff in compare_properties!(emacs) { + match diff { + ComparePropertiesResult::NoChange => {} + ComparePropertiesResult::SelfChange(new_status, new_message) => { + this_status = new_status; + message = new_message + } + ComparePropertiesResult::DiffEntry(diff_entry) => child_status.push(diff_entry), + } } Ok(DiffResult { status: this_status, name: rust.get_elisp_name(), message, - children: Vec::new(), + children: child_status, rust_source: rust.get_source(), emacs_token: emacs, } @@ -2683,16 +2703,18 @@ fn compare_underline<'b, 's>( } fn compare_verbatim<'b, 's>( - _source: &'s str, + source: &'s str, emacs: &'b Token<'s>, rust: &'b Verbatim<'s>, ) -> Result, Box> { let mut this_status = DiffStatus::Good; + let mut child_status = Vec::new(); let mut message = None; assert_no_children(emacs, &mut this_status, &mut message)?; - if let Some((new_status, new_message)) = compare_properties!( + for diff in compare_properties!( + source, emacs, rust, ( @@ -2700,16 +2722,22 @@ fn compare_verbatim<'b, 's>( |r| Some(r.contents), compare_property_quoted_string ) - )? { - this_status = new_status; - message = new_message; + ) { + match diff { + ComparePropertiesResult::NoChange => {} + ComparePropertiesResult::SelfChange(new_status, new_message) => { + this_status = new_status; + message = new_message + } + ComparePropertiesResult::DiffEntry(diff_entry) => child_status.push(diff_entry), + } } Ok(DiffResult { status: this_status, name: rust.get_elisp_name(), message, - children: Vec::new(), + children: child_status, rust_source: rust.get_source(), emacs_token: emacs, } @@ -2717,16 +2745,18 @@ fn compare_verbatim<'b, 's>( } fn compare_code<'b, 's>( - _source: &'s str, + source: &'s str, emacs: &'b Token<'s>, rust: &'b Code<'s>, ) -> Result, Box> { let mut this_status = DiffStatus::Good; + let mut child_status = Vec::new(); let mut message = None; assert_no_children(emacs, &mut this_status, &mut message)?; - if let Some((new_status, new_message)) = compare_properties!( + for diff in compare_properties!( + source, emacs, rust, ( @@ -2734,16 +2764,22 @@ fn compare_code<'b, 's>( |r| Some(r.contents), compare_property_quoted_string ) - )? { - this_status = new_status; - message = new_message; + ) { + match diff { + ComparePropertiesResult::NoChange => {} + ComparePropertiesResult::SelfChange(new_status, new_message) => { + this_status = new_status; + message = new_message + } + ComparePropertiesResult::DiffEntry(diff_entry) => child_status.push(diff_entry), + } } Ok(DiffResult { status: this_status, name: rust.get_elisp_name(), message, - children: Vec::new(), + children: child_status, rust_source: rust.get_source(), emacs_token: emacs, } @@ -2768,16 +2804,22 @@ fn compare_strike_through<'b, 's>( &mut message, )?; - if let Some((new_status, new_message)) = compare_properties!(emacs)? { - this_status = new_status; - message = new_message; + for diff in compare_properties!(emacs) { + match diff { + ComparePropertiesResult::NoChange => {} + ComparePropertiesResult::SelfChange(new_status, new_message) => { + this_status = new_status; + message = new_message + } + ComparePropertiesResult::DiffEntry(diff_entry) => child_status.push(diff_entry), + } } Ok(DiffResult { status: this_status, name: rust.get_elisp_name(), message, - children: Vec::new(), + children: child_status, rust_source: rust.get_source(), emacs_token: emacs, } @@ -2802,7 +2844,8 @@ fn compare_regular_link<'b, 's>( &mut message, )?; - if let Some((new_status, new_message)) = compare_properties!( + for diff in compare_properties!( + source, emacs, rust, ( @@ -2844,16 +2887,22 @@ fn compare_regular_link<'b, 's>( |r| r.get_search_option(), compare_property_quoted_string ) - )? { - this_status = new_status; - message = new_message; + ) { + match diff { + ComparePropertiesResult::NoChange => {} + ComparePropertiesResult::SelfChange(new_status, new_message) => { + this_status = new_status; + message = new_message + } + ComparePropertiesResult::DiffEntry(diff_entry) => child_status.push(diff_entry), + } } Ok(DiffResult { status: this_status, name: rust.get_elisp_name(), message, - children: Vec::new(), + children: child_status, rust_source: rust.get_source(), emacs_token: emacs, } @@ -2878,7 +2927,8 @@ fn compare_radio_link<'b, 's>( &mut message, )?; - if let Some((new_status, new_message)) = compare_properties!( + for diff in compare_properties!( + source, emacs, rust, ( @@ -2911,16 +2961,22 @@ fn compare_radio_link<'b, 's>( compare_identity, compare_property_always_nil ) - )? { - this_status = new_status; - message = new_message; + ) { + match diff { + ComparePropertiesResult::NoChange => {} + ComparePropertiesResult::SelfChange(new_status, new_message) => { + this_status = new_status; + message = new_message + } + ComparePropertiesResult::DiffEntry(diff_entry) => child_status.push(diff_entry), + } } Ok(DiffResult { status: this_status, name: rust.get_elisp_name(), message, - children: Vec::new(), + children: child_status, rust_source: rust.get_source(), emacs_token: emacs, } @@ -2945,7 +3001,8 @@ fn compare_radio_target<'b, 's>( &mut message, )?; - if let Some((new_status, new_message)) = compare_properties!( + for diff in compare_properties!( + source, emacs, rust, ( @@ -2953,16 +3010,22 @@ fn compare_radio_target<'b, 's>( |r| Some(r.value), compare_property_quoted_string ) - )? { - this_status = new_status; - message = new_message; + ) { + match diff { + ComparePropertiesResult::NoChange => {} + ComparePropertiesResult::SelfChange(new_status, new_message) => { + this_status = new_status; + message = new_message + } + ComparePropertiesResult::DiffEntry(diff_entry) => child_status.push(diff_entry), + } } Ok(DiffResult { status: this_status, name: rust.get_elisp_name(), message, - children: Vec::new(), + children: child_status, rust_source: rust.get_source(), emacs_token: emacs, } @@ -2970,16 +3033,18 @@ fn compare_radio_target<'b, 's>( } fn compare_plain_link<'b, 's>( - _source: &'s str, + source: &'s str, emacs: &'b Token<'s>, rust: &'b PlainLink<'s>, ) -> Result, Box> { let mut this_status = DiffStatus::Good; + let mut child_status = Vec::new(); let mut message = None; assert_no_children(emacs, &mut this_status, &mut message)?; - if let Some((new_status, new_message)) = compare_properties!( + for diff in compare_properties!( + source, emacs, rust, ( @@ -3021,16 +3086,22 @@ fn compare_plain_link<'b, 's>( |r| r.search_option, compare_property_quoted_string ) - )? { - this_status = new_status; - message = new_message; + ) { + match diff { + ComparePropertiesResult::NoChange => {} + ComparePropertiesResult::SelfChange(new_status, new_message) => { + this_status = new_status; + message = new_message + } + ComparePropertiesResult::DiffEntry(diff_entry) => child_status.push(diff_entry), + } } Ok(DiffResult { status: this_status, name: rust.get_elisp_name(), message, - children: Vec::new(), + children: child_status, rust_source: rust.get_source(), emacs_token: emacs, } @@ -3038,16 +3109,18 @@ fn compare_plain_link<'b, 's>( } fn compare_angle_link<'b, 's>( - _source: &'s str, + source: &'s str, emacs: &'b Token<'s>, rust: &'b AngleLink<'s>, ) -> Result, Box> { let mut this_status = DiffStatus::Good; + let mut child_status = Vec::new(); let mut message = None; assert_no_children(emacs, &mut this_status, &mut message)?; - if let Some((new_status, new_message)) = compare_properties!( + for diff in compare_properties!( + source, emacs, rust, ( @@ -3089,16 +3162,22 @@ fn compare_angle_link<'b, 's>( |r| r.get_search_option(), compare_property_quoted_string ) - )? { - this_status = new_status; - message = new_message; + ) { + match diff { + ComparePropertiesResult::NoChange => {} + ComparePropertiesResult::SelfChange(new_status, new_message) => { + this_status = new_status; + message = new_message + } + ComparePropertiesResult::DiffEntry(diff_entry) => child_status.push(diff_entry), + } } Ok(DiffResult { status: this_status, name: rust.get_elisp_name(), message, - children: Vec::new(), + children: child_status, rust_source: rust.get_source(), emacs_token: emacs, } @@ -3106,16 +3185,18 @@ fn compare_angle_link<'b, 's>( } fn compare_org_macro<'b, 's>( - _source: &'s str, + source: &'s str, emacs: &'b Token<'s>, rust: &'b OrgMacro<'s>, ) -> Result, Box> { let mut this_status = DiffStatus::Good; + let mut child_status = Vec::new(); let mut message = None; assert_no_children(emacs, &mut this_status, &mut message)?; - if let Some((new_status, new_message)) = compare_properties!( + for diff in compare_properties!( + source, emacs, rust, ( @@ -3137,16 +3218,22 @@ fn compare_org_macro<'b, 's>( }, compare_property_list_of_quoted_string ) - )? { - this_status = new_status; - message = new_message; + ) { + match diff { + ComparePropertiesResult::NoChange => {} + ComparePropertiesResult::SelfChange(new_status, new_message) => { + this_status = new_status; + message = new_message + } + ComparePropertiesResult::DiffEntry(diff_entry) => child_status.push(diff_entry), + } } Ok(DiffResult { status: this_status, name: rust.get_elisp_name(), message, - children: Vec::new(), + children: child_status, rust_source: rust.get_source(), emacs_token: emacs, } @@ -3154,16 +3241,18 @@ fn compare_org_macro<'b, 's>( } fn compare_entity<'b, 's>( - _source: &'s str, + source: &'s str, emacs: &'b Token<'s>, rust: &'b Entity<'s>, ) -> Result, Box> { let mut this_status = DiffStatus::Good; + let mut child_status = Vec::new(); let mut message = None; assert_no_children(emacs, &mut this_status, &mut message)?; - if let Some((new_status, new_message)) = compare_properties!( + for diff in compare_properties!( + source, emacs, rust, ( @@ -3207,16 +3296,22 @@ fn compare_entity<'b, 's>( |r| r.use_brackets, compare_property_boolean ) - )? { - this_status = new_status; - message = new_message; + ) { + match diff { + ComparePropertiesResult::NoChange => {} + ComparePropertiesResult::SelfChange(new_status, new_message) => { + this_status = new_status; + message = new_message + } + ComparePropertiesResult::DiffEntry(diff_entry) => child_status.push(diff_entry), + } } Ok(DiffResult { status: this_status, name: rust.get_elisp_name(), message, - children: Vec::new(), + children: child_status, rust_source: rust.get_source(), emacs_token: emacs, } @@ -3224,16 +3319,18 @@ fn compare_entity<'b, 's>( } fn compare_latex_fragment<'b, 's>( - _source: &'s str, + source: &'s str, emacs: &'b Token<'s>, rust: &'b LatexFragment<'s>, ) -> Result, Box> { let mut this_status = DiffStatus::Good; + let mut child_status = Vec::new(); let mut message = None; assert_no_children(emacs, &mut this_status, &mut message)?; - if let Some((new_status, new_message)) = compare_properties!( + for diff in compare_properties!( + source, emacs, rust, ( @@ -3241,16 +3338,22 @@ fn compare_latex_fragment<'b, 's>( |r| Some(r.value), compare_property_quoted_string ) - )? { - this_status = new_status; - message = new_message; + ) { + match diff { + ComparePropertiesResult::NoChange => {} + ComparePropertiesResult::SelfChange(new_status, new_message) => { + this_status = new_status; + message = new_message + } + ComparePropertiesResult::DiffEntry(diff_entry) => child_status.push(diff_entry), + } } Ok(DiffResult { status: this_status, name: rust.get_elisp_name(), message, - children: Vec::new(), + children: child_status, rust_source: rust.get_source(), emacs_token: emacs, } @@ -3258,16 +3361,18 @@ fn compare_latex_fragment<'b, 's>( } fn compare_export_snippet<'b, 's>( - _source: &'s str, + source: &'s str, emacs: &'b Token<'s>, rust: &'b ExportSnippet<'s>, ) -> Result, Box> { let mut this_status = DiffStatus::Good; + let mut child_status = Vec::new(); let mut message = None; assert_no_children(emacs, &mut this_status, &mut message)?; - if let Some((new_status, new_message)) = compare_properties!( + for diff in compare_properties!( + source, emacs, rust, ( @@ -3280,16 +3385,22 @@ fn compare_export_snippet<'b, 's>( |r| r.contents, compare_property_quoted_string ) - )? { - this_status = new_status; - message = new_message; + ) { + match diff { + ComparePropertiesResult::NoChange => {} + ComparePropertiesResult::SelfChange(new_status, new_message) => { + this_status = new_status; + message = new_message + } + ComparePropertiesResult::DiffEntry(diff_entry) => child_status.push(diff_entry), + } } Ok(DiffResult { status: this_status, name: rust.get_elisp_name(), message, - children: Vec::new(), + children: child_status, rust_source: rust.get_source(), emacs_token: emacs, } @@ -3314,7 +3425,8 @@ fn compare_footnote_reference<'b, 's>( &mut message, )?; - if let Some((new_status, new_message)) = compare_properties!( + for diff in compare_properties!( + source, emacs, rust, ( @@ -3330,9 +3442,15 @@ fn compare_footnote_reference<'b, 's>( }), compare_property_unquoted_atom ) - )? { - this_status = new_status; - message = new_message; + ) { + match diff { + ComparePropertiesResult::NoChange => {} + ComparePropertiesResult::SelfChange(new_status, new_message) => { + this_status = new_status; + message = new_message + } + ComparePropertiesResult::DiffEntry(diff_entry) => child_status.push(diff_entry), + } } Ok(DiffResult { @@ -3347,20 +3465,66 @@ fn compare_footnote_reference<'b, 's>( } fn compare_citation<'b, 's>( - _source: &'s str, + source: &'s str, emacs: &'b Token<'s>, rust: &'b Citation<'s>, ) -> Result, Box> { - let this_status = DiffStatus::Good; - let message = None; + let mut child_status = Vec::new(); + let mut this_status = DiffStatus::Good; + let mut message = None; - // TODO: Compare :style :prefix :suffix + compare_children( + source, + emacs, + &rust.children, + &mut child_status, + &mut this_status, + &mut message, + )?; + + for diff in compare_properties!( + source, + emacs, + rust, + ( + EmacsField::Required(":style"), + |r| r.style, + compare_property_quoted_string + ), + ( + EmacsField::Optional(":prefix"), + |r| if r.prefix.is_empty() { + None + } else { + Some(r.prefix.iter()) + }, + compare_property_list_of_ast_nodes + ), + ( + EmacsField::Optional(":suffix"), + |r| if r.suffix.is_empty() { + None + } else { + Some(r.suffix.iter()) + }, + compare_property_list_of_ast_nodes + ) + ) { + match diff { + ComparePropertiesResult::NoChange => {} + ComparePropertiesResult::SelfChange(new_status, new_message) => { + this_status = new_status; + message = new_message + } + ComparePropertiesResult::DiffEntry(diff_entry) => child_status.push(diff_entry), + } + } Ok(DiffResult { status: this_status, name: rust.get_elisp_name(), message, - children: Vec::new(), + children: child_status, rust_source: rust.get_source(), emacs_token: emacs, } @@ -3368,20 +3532,59 @@ fn compare_citation<'b, 's>( } fn compare_citation_reference<'b, 's>( - _source: &'s str, + source: &'s str, emacs: &'b Token<'s>, rust: &'b CitationReference<'s>, ) -> Result, Box> { - let this_status = DiffStatus::Good; - let message = None; + let mut this_status = DiffStatus::Good; + let mut child_status = Vec::new(); + let mut message = None; - // TODO: Compare :key :prefix :suffix + assert_no_children(emacs, &mut this_status, &mut message)?; + + for diff in compare_properties!( + source, + emacs, + rust, + ( + EmacsField::Required(":key"), + |r| Some(r.key), + compare_property_quoted_string + ), + ( + EmacsField::Optional(":prefix"), + |r| if r.prefix.is_empty() { + None + } else { + Some(r.prefix.iter()) + }, + compare_property_list_of_ast_nodes + ), + ( + EmacsField::Optional(":suffix"), + |r| if r.suffix.is_empty() { + None + } else { + Some(r.suffix.iter()) + }, + compare_property_list_of_ast_nodes + ) + ) { + match diff { + ComparePropertiesResult::NoChange => {} + ComparePropertiesResult::SelfChange(new_status, new_message) => { + this_status = new_status; + message = new_message + } + ComparePropertiesResult::DiffEntry(diff_entry) => child_status.push(diff_entry), + } + } Ok(DiffResult { status: this_status, name: rust.get_elisp_name(), message, - children: Vec::new(), + children: child_status, rust_source: rust.get_source(), emacs_token: emacs, } diff --git a/src/compare/macros.rs b/src/compare/macros.rs index c71ce9d..1ebe391 100644 --- a/src/compare/macros.rs +++ b/src/compare/macros.rs @@ -30,10 +30,9 @@ /// } /// ``` macro_rules! compare_properties { - ($emacs:expr, $rust:expr, $(($emacs_field:expr, $rust_value_getter:expr, $compare_fn: expr)),+) => { + ($source:expr, $emacs:expr, $rust:expr, $(($emacs_field:expr, $rust_value_getter:expr, $compare_fn: expr)),+) => { { - let mut this_status = DiffStatus::Good; - let mut message: Option = None; + let mut new_status = Vec::new(); let children = $emacs.as_list()?; let attributes_child = children .iter() @@ -44,10 +43,9 @@ macro_rules! compare_properties { if emacs_keys.contains(":standard-properties") { emacs_keys.remove(":standard-properties"); } else { - this_status = DiffStatus::Bad; - message = Some(format!( + new_status.push(ComparePropertiesResult::SelfChange(DiffStatus::Bad, Some(format!( "Emacs token lacks :standard-properties field.", - )); + )))); } $( match $emacs_field { @@ -58,11 +56,10 @@ macro_rules! compare_properties { emacs_keys.remove(name); }, EmacsField::Required(name) => { - this_status = DiffStatus::Bad; - message = Some(format!( + new_status.push(ComparePropertiesResult::SelfChange(DiffStatus::Bad, Some(format!( "Emacs token lacks required field: {}", name - )); + )))); }, EmacsField::Optional(_name) => {}, } @@ -71,11 +68,10 @@ macro_rules! compare_properties { if !emacs_keys.is_empty() { let unexpected_keys: Vec<&str> = emacs_keys.into_iter().collect(); let unexpected_keys = unexpected_keys.join(", "); - this_status = DiffStatus::Bad; - message = Some(format!( + new_status.push(ComparePropertiesResult::SelfChange(DiffStatus::Bad, Some(format!( "Emacs token had extra field(s): {}", unexpected_keys - )); + )))); } $( @@ -87,33 +83,23 @@ macro_rules! compare_properties { name }, }; - let result = $compare_fn($emacs, $rust, emacs_name, $rust_value_getter)?; + let result = $compare_fn($source, $emacs, $rust, emacs_name, $rust_value_getter)?; match result { - Some((DiffStatus::Good, _)) => unreachable!("No comparison functions should return Some() when DiffStatus is good."), - Some((status, msg)) => { - this_status = status; - message = msg; - }, - _ => {} + ComparePropertiesResult::SelfChange(DiffStatus::Good, _) => unreachable!("No comparison functions should return SelfChange() when DiffStatus is good."), + ComparePropertiesResult::NoChange => {}, + result => { + new_status.push(result); + } } )+ - match this_status { - DiffStatus::Good => { - let result: Result<_, Box> = Ok(None); - result - }, - _ => { - Ok(Some((this_status, message))) - } - } + new_status } }; // Default case for when there are no expected properties except for :standard-properties ($emacs:expr) => { { - let mut this_status = DiffStatus::Good; - let mut message: Option = None; + let mut new_status = Vec::new(); let children = $emacs.as_list()?; let attributes_child = children .iter() @@ -124,30 +110,20 @@ macro_rules! compare_properties { if emacs_keys.contains(":standard-properties") { emacs_keys.remove(":standard-properties"); } else { - this_status = DiffStatus::Bad; - message = Some(format!( + new_status.push(ComparePropertiesResult::SelfChange(DiffStatus::Bad, Some(format!( "Emacs token lacks :standard-properties field.", - )); + )))); } if !emacs_keys.is_empty() { let unexpected_keys: Vec<&str> = emacs_keys.into_iter().collect(); let unexpected_keys = unexpected_keys.join(", "); - this_status = DiffStatus::Bad; - message = Some(format!( + new_status.push(ComparePropertiesResult::SelfChange(DiffStatus::Bad, Some(format!( "Emacs token had extra field(s): {}", unexpected_keys - )); - } - match this_status { - DiffStatus::Good => { - let result: Result<_, Box> = Ok(None); - result - }, - _ => { - Ok(Some((this_status, message))) - } + )))); } + new_status } }; } diff --git a/src/context/context.rs b/src/context/context.rs index 6787273..b49d76e 100644 --- a/src/context/context.rs +++ b/src/context/context.rs @@ -33,11 +33,6 @@ pub(crate) enum ContextElement<'r, 's> { /// The value stored is the start of the element after the affiliated keywords. In this way, we can ensure that we do not exit an element immediately after the affiliated keyword had been consumed. HasAffiliatedKeyword(HasAffiliatedKeywordInner<'r, 's>), - /// Indicate the position that we started parsing a text section. - /// - /// This value is stored because "<<<" is not a valid prefix for text markup UNLESS it is starting a radio target. Likewise "[" is not a valid prefix for text markup UNLESS it is the start of a regular link description. - StartTextSection(OrgSource<'s>), - /// This is just here to use the 's lifetime until I'm sure we can eliminate it from ContextElement. #[allow(dead_code)] Placeholder(PhantomData<&'s str>), @@ -121,7 +116,10 @@ impl<'g, 'r, 's> Context<'g, 'r, 's> { } } - #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] + #[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(self)) + )] pub(crate) fn check_exit_matcher( &'r self, i: OrgSource<'s>, @@ -168,7 +166,10 @@ impl<'g, 'r, 's> Context<'g, 'r, 's> { } } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(_context)) +)] fn document_end<'b, 'g, 'r, 's>( _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, diff --git a/src/parser/angle_link.rs b/src/parser/angle_link.rs index cffa533..8cd21a7 100644 --- a/src/parser/angle_link.rs +++ b/src/parser/angle_link.rs @@ -29,7 +29,10 @@ use crate::parser::util::get_consumed; use crate::types::AngleLink; use crate::types::LinkType; -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] pub(crate) fn angle_link<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -68,7 +71,10 @@ struct PathAngle<'s> { application: Option<&'s str>, } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn path_angle<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -83,7 +89,10 @@ fn path_angle<'b, 'g, 'r, 's>( Ok((remaining, path)) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(_context)) +)] fn path_angle_end<'b, 'g, 'r, 's>( _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -91,7 +100,10 @@ fn path_angle_end<'b, 'g, 'r, 's>( tag(">")(input) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn parse_angle_link<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -102,7 +114,10 @@ fn parse_angle_link<'b, 'g, 'r, 's>( ))(input) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn parse_file_angle_link<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -137,7 +152,10 @@ fn parse_file_angle_link<'b, 'g, 'r, 's>( )) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn parse_protocol_angle_link<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, diff --git a/src/parser/babel_call.rs b/src/parser/babel_call.rs index 6903444..cafb83e 100644 --- a/src/parser/babel_call.rs +++ b/src/parser/babel_call.rs @@ -29,7 +29,10 @@ use crate::parser::util::get_consumed; use crate::parser::util::org_line_ending; use crate::types::BabelCall; -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] pub(crate) fn babel_call<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, diff --git a/src/parser/citation.rs b/src/parser/citation.rs index a56beab..aae1540 100644 --- a/src/parser/citation.rs +++ b/src/parser/citation.rs @@ -2,6 +2,7 @@ use nom::branch::alt; use nom::bytes::complete::tag; use nom::bytes::complete::tag_no_case; use nom::character::complete::anychar; +use nom::combinator::map; use nom::combinator::opt; use nom::combinator::recognize; use nom::combinator::verify; @@ -30,24 +31,27 @@ use crate::parser::util::get_consumed; use crate::types::Citation; use crate::types::Object; -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] pub(crate) fn citation<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, Citation<'s>> { // TODO: Despite being a standard object, citations cannot exist inside the global prefix/suffix for other citations because citations must contain something that matches @key which is forbidden inside the global prefix/suffix. This TODO is to evaluate if its worth putting in an explicit check for this (which can be easily accomplished by checking the output of `get_bracket_depth()`). I suspect its not worth it because I expect, outside of intentionally crafted inputs, this parser will exit immediately inside a citation since it is unlikely to find the "[cite" substring inside a citation global prefix/suffix. let (remaining, _) = tag_no_case("[cite")(input)?; - let (remaining, _) = opt(citestyle)(remaining)?; + let (remaining, style) = opt(citestyle)(remaining)?; let (remaining, _) = tag(":")(remaining)?; - let (remaining, _prefix) = + let (remaining, prefix) = must_balance_bracket(opt(parser_with_context!(global_prefix)(context)))(remaining)?; - let (remaining, _references) = + let (remaining, references) = separated_list1(tag(";"), parser_with_context!(citation_reference)(context))(remaining)?; - let (remaining, _suffix) = must_balance_bracket(opt(tuple(( - tag(";"), - parser_with_context!(global_suffix)(context), - ))))(remaining)?; + let (remaining, suffix) = must_balance_bracket(opt(map( + tuple((tag(";"), parser_with_context!(global_suffix)(context))), + |(_, suffix)| suffix, + )))(remaining)?; let (remaining, _) = tag("]")(remaining)?; let (remaining, _trailing_whitespace) = maybe_consume_object_trailing_whitespace_if_not_exiting(context, remaining)?; @@ -56,16 +60,23 @@ pub(crate) fn citation<'b, 'g, 'r, 's>( remaining, Citation { source: source.into(), + style: style.map(Into::<&str>::into), + prefix: prefix.unwrap_or(Vec::new()), + suffix: suffix.unwrap_or(Vec::new()), + children: references, }, )) } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn citestyle<'s>(input: OrgSource<'s>) -> Res, OrgSource<'s>> { - let (remaining, _) = tuple((tag("/"), style))(input)?; - let (remaining, _) = opt(tuple((tag("/"), variant)))(remaining)?; - let source = get_consumed(input, remaining); - Ok((remaining, source)) + map( + tuple(( + tag("/"), + recognize(tuple((style, opt(tuple((tag("/"), variant)))))), + )), + |(_, style)| style, + )(input) } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] @@ -82,7 +93,10 @@ fn variant<'s>(input: OrgSource<'s>) -> Res, OrgSource<'s>> { })))(input) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn global_prefix<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -108,7 +122,10 @@ fn global_prefix_end(starting_bracket_depth: BracketDepth) -> impl ContextMatche move |context, input: OrgSource<'_>| _global_prefix_end(context, input, starting_bracket_depth) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn _global_prefix_end<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -131,7 +148,10 @@ fn _global_prefix_end<'b, 'g, 'r, 's>( ))(input) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn global_suffix<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -156,7 +176,10 @@ fn global_suffix_end(starting_bracket_depth: BracketDepth) -> impl ContextMatche move |context, input: OrgSource<'_>| _global_suffix_end(context, input, starting_bracket_depth) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn _global_suffix_end<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -186,6 +209,7 @@ mod tests { use crate::context::GlobalSettings; use crate::context::List; use crate::parser::element_parser::element; + use crate::types::CitationReference; use crate::types::Element; use crate::types::GetStandardProperties; @@ -213,7 +237,16 @@ mod tests { .get(0) .expect("Len already asserted to be 1"), &Object::Citation(Citation { - source: "[cite:@foo]" + source: "[cite:@foo]", + style: None, + prefix: vec![], + suffix: vec![], + children: vec![CitationReference { + source: "@foo", + key: "foo", + prefix: vec![], + suffix: vec![] + }] }) ); } diff --git a/src/parser/citation_reference.rs b/src/parser/citation_reference.rs index 696d9a4..ed5f594 100644 --- a/src/parser/citation_reference.rs +++ b/src/parser/citation_reference.rs @@ -1,6 +1,7 @@ use nom::branch::alt; use nom::bytes::complete::tag; use nom::character::complete::anychar; +use nom::combinator::map; use nom::combinator::not; use nom::combinator::opt; use nom::combinator::recognize; @@ -28,47 +29,65 @@ use crate::parser::util::WORD_CONSTITUENT_CHARACTERS; use crate::types::CitationReference; use crate::types::Object; -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] pub(crate) fn citation_reference<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, CitationReference<'s>> { - let (remaining, _prefix) = + let (remaining, prefix) = must_balance_bracket(opt(parser_with_context!(key_prefix)(context)))(input)?; - let (remaining, _key) = parser_with_context!(citation_reference_key)(context)(remaining)?; - let (remaining, _suffix) = + let (remaining, key) = parser_with_context!(citation_reference_key)(context)(remaining)?; + let (remaining, suffix) = must_balance_bracket(opt(parser_with_context!(key_suffix)(context)))(remaining)?; + let without_closing_semi_remaining = remaining; + let (remaining, _closing_semi) = opt(tag(";"))(remaining)?; let source = get_consumed(input, remaining); Ok(( - remaining, + without_closing_semi_remaining, CitationReference { source: source.into(), + key: key.into(), + prefix: prefix.unwrap_or(Vec::new()), + suffix: suffix.unwrap_or(Vec::new()), }, )) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] pub(crate) fn citation_reference_key<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { - let (remaining, source) = recognize(tuple(( - tag("@"), - many1(verify( - preceded( - not(parser_with_context!(exit_matcher_parser)(context)), - anychar, - ), - |c| { - WORD_CONSTITUENT_CHARACTERS.contains(*c) || "-.:?~`'/*@+|(){}<>&_^$#%~".contains(*c) - }, + let (remaining, source) = map( + tuple(( + tag("@"), + recognize(many1(verify( + preceded( + not(parser_with_context!(exit_matcher_parser)(context)), + anychar, + ), + |c| { + WORD_CONSTITUENT_CHARACTERS.contains(*c) + || "-.:?~`'/*@+|(){}<>&_^$#%~".contains(*c) + }, + ))), )), - )))(input)?; + |(_, key)| key, + )(input)?; Ok((remaining, source)) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn key_prefix<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -89,7 +108,10 @@ fn key_prefix<'b, 'g, 'r, 's>( Ok((remaining, children)) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn key_suffix<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -114,7 +136,10 @@ fn key_prefix_end(starting_bracket_depth: BracketDepth) -> impl ContextMatcher { move |context, input: OrgSource<'_>| _key_prefix_end(context, input, starting_bracket_depth) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn _key_prefix_end<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -141,7 +166,10 @@ fn key_suffix_end(starting_bracket_depth: BracketDepth) -> impl ContextMatcher { move |context, input: OrgSource<'_>| _key_suffix_end(context, input, starting_bracket_depth) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(_context)) +)] fn _key_suffix_end<'b, 'g, 'r, 's>( _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, diff --git a/src/parser/clock.rs b/src/parser/clock.rs index 9941510..e25dd39 100644 --- a/src/parser/clock.rs +++ b/src/parser/clock.rs @@ -24,7 +24,10 @@ use crate::types::Clock; use crate::types::ClockStatus; use crate::types::Timestamp; -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] pub(crate) fn clock<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -55,7 +58,10 @@ pub(crate) fn clock<'b, 'g, 'r, 's>( )) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn clock_timestamp<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, diff --git a/src/parser/comment.rs b/src/parser/comment.rs index 09d74e5..8c46e56 100644 --- a/src/parser/comment.rs +++ b/src/parser/comment.rs @@ -26,7 +26,10 @@ use crate::parser::util::immediate_in_section; use crate::parser::util::start_of_line; use crate::types::Comment; -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] pub(crate) fn comment<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -69,7 +72,10 @@ pub(crate) fn comment<'b, 'g, 'r, 's>( )) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(_context)) +)] fn comment_line<'b, 'g, 'r, 's>( _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, diff --git a/src/parser/diary_sexp.rs b/src/parser/diary_sexp.rs index 7e3d173..7b667ab 100644 --- a/src/parser/diary_sexp.rs +++ b/src/parser/diary_sexp.rs @@ -15,7 +15,10 @@ use crate::parser::util::get_consumed; use crate::parser::util::start_of_line; use crate::types::DiarySexp; -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] pub(crate) fn diary_sexp<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, diff --git a/src/parser/document.rs b/src/parser/document.rs index 4901173..23baa30 100644 --- a/src/parser/document.rs +++ b/src/parser/document.rs @@ -109,7 +109,7 @@ fn document<'b, 'g, 'r, 's>( Ok((Into::<&str>::into(remaining), doc)) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug", skip(context)))] #[allow(dead_code)] fn document_org_source<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, @@ -186,7 +186,7 @@ fn document_org_source<'b, 'g, 'r, 's>( Ok((remaining.into(), document)) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug", skip(context)))] fn _document<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, diff --git a/src/parser/drawer.rs b/src/parser/drawer.rs index 2cd3256..36fda09 100644 --- a/src/parser/drawer.rs +++ b/src/parser/drawer.rs @@ -35,7 +35,10 @@ use crate::types::Element; use crate::types::Paragraph; use crate::types::SetSource; -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] pub(crate) fn drawer<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -109,7 +112,10 @@ fn name<'s>(input: OrgSource<'s>) -> Res, OrgSource<'s>> { take_while(|c| WORD_CONSTITUENT_CHARACTERS.contains(c) || "-_".contains(c))(input) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(_context)) +)] fn drawer_end<'b, 'g, 'r, 's>( _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, diff --git a/src/parser/dynamic_block.rs b/src/parser/dynamic_block.rs index 39f43c8..8bd0739 100644 --- a/src/parser/dynamic_block.rs +++ b/src/parser/dynamic_block.rs @@ -40,7 +40,10 @@ use crate::types::Element; use crate::types::Paragraph; use crate::types::SetSource; -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] pub(crate) fn dynamic_block<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -122,7 +125,10 @@ fn parameters<'s>(input: OrgSource<'s>) -> Res, OrgSource<'s>> { recognize(many_till(anychar, peek(tuple((space0, line_ending)))))(input) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(_context)) +)] fn dynamic_block_end<'b, 'g, 'r, 's>( _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, diff --git a/src/parser/element_parser.rs b/src/parser/element_parser.rs index ead31e6..b17068e 100644 --- a/src/parser/element_parser.rs +++ b/src/parser/element_parser.rs @@ -51,7 +51,7 @@ pub(crate) const fn element( move |context, input: OrgSource<'_>| _element(context, input, can_be_paragraph) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug", skip(context)))] fn _element<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -177,7 +177,7 @@ pub(crate) const fn detect_element( move |context, input: OrgSource<'_>| _detect_element(context, input, can_be_paragraph) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug", skip(context)))] fn _detect_element<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, diff --git a/src/parser/entity.rs b/src/parser/entity.rs index 022545d..dec6ba5 100644 --- a/src/parser/entity.rs +++ b/src/parser/entity.rs @@ -18,7 +18,10 @@ use crate::error::Res; use crate::parser::util::get_consumed; use crate::types::Entity; -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] pub(crate) fn entity<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -45,7 +48,10 @@ pub(crate) fn entity<'b, 'g, 'r, 's>( )) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn name<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, diff --git a/src/parser/export_snippet.rs b/src/parser/export_snippet.rs index 5b99f39..c588f5f 100644 --- a/src/parser/export_snippet.rs +++ b/src/parser/export_snippet.rs @@ -19,7 +19,10 @@ use crate::parser::util::exit_matcher_parser; use crate::parser::util::get_consumed; use crate::types::ExportSnippet; -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] pub(crate) fn export_snippet<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -49,7 +52,10 @@ pub(crate) fn export_snippet<'b, 'g, 'r, 's>( )) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(_context)) +)] fn backend<'b, 'g, 'r, 's>( _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -60,7 +66,10 @@ fn backend<'b, 'g, 'r, 's>( Ok((remaining, backend_name)) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn contents<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -72,7 +81,10 @@ fn contents<'b, 'g, 'r, 's>( Ok((remaining, source)) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(_context)) +)] fn export_snippet_end<'b, 'g, 'r, 's>( _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, diff --git a/src/parser/fixed_width_area.rs b/src/parser/fixed_width_area.rs index 466eb59..4025c8e 100644 --- a/src/parser/fixed_width_area.rs +++ b/src/parser/fixed_width_area.rs @@ -22,7 +22,10 @@ use crate::parser::util::get_consumed; use crate::parser::util::start_of_line; use crate::types::FixedWidthArea; -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] pub(crate) fn fixed_width_area<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -60,7 +63,10 @@ pub(crate) fn fixed_width_area<'b, 'g, 'r, 's>( )) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(_context)) +)] fn fixed_width_area_line<'b, 'g, 'r, 's>( _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, diff --git a/src/parser/footnote_definition.rs b/src/parser/footnote_definition.rs index 4a182e3..3386c59 100644 --- a/src/parser/footnote_definition.rs +++ b/src/parser/footnote_definition.rs @@ -34,7 +34,10 @@ use crate::parser::util::maybe_consume_trailing_whitespace; use crate::parser::util::start_of_line; use crate::types::FootnoteDefinition; -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] pub(crate) fn footnote_definition<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -103,7 +106,10 @@ pub(crate) fn label<'s>(input: OrgSource<'s>) -> Res, OrgSource<'s take_while(|c| WORD_CONSTITUENT_CHARACTERS.contains(c) || "-_".contains(c))(input) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn footnote_definition_end<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, diff --git a/src/parser/footnote_reference.rs b/src/parser/footnote_reference.rs index 1247a70..7e4e2c6 100644 --- a/src/parser/footnote_reference.rs +++ b/src/parser/footnote_reference.rs @@ -1,28 +1,36 @@ use nom::branch::alt; use nom::bytes::complete::tag; use nom::bytes::complete::tag_no_case; +use nom::combinator::all_consuming; +use nom::combinator::map_parser; use nom::combinator::verify; -use nom::multi::many_till; +use nom::multi::many1; use super::org_source::BracketDepth; use super::org_source::OrgSource; +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::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; use crate::error::Res; use crate::parser::footnote_definition::label; use crate::parser::object_parser::standard_set_object; -use crate::parser::util::exit_matcher_parser; use crate::parser::util::get_consumed; use crate::types::FootnoteReference; -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] pub(crate) fn footnote_reference<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -34,7 +42,10 @@ pub(crate) fn footnote_reference<'b, 'g, 'r, 's>( ))(input) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn anonymous_footnote<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -46,13 +57,21 @@ fn anonymous_footnote<'b, 'g, 'r, 's>( exit_matcher: &exit_with_depth, }); let parser_context = context.with_additional_node(&parser_context); - let (remaining, (children, _exit_contents)) = verify( - many_till( - parser_with_context!(standard_set_object)(&parser_context), - parser_with_context!(exit_matcher_parser)(&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), + |text| text.len() > 0, ), - |(children, _exit_contents)| !children.is_empty(), + confine_context(|i| { + all_consuming(many1(parser_with_context!(standard_set_object)( + &initial_context, + )))(i) + }), )(remaining)?; + let (remaining, _) = tag("]")(remaining)?; let (remaining, _trailing_whitespace) = @@ -68,7 +87,10 @@ fn anonymous_footnote<'b, 'g, 'r, 's>( )) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn inline_footnote<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -82,13 +104,21 @@ fn inline_footnote<'b, 'g, 'r, 's>( exit_matcher: &exit_with_depth, }); let parser_context = context.with_additional_node(&parser_context); - let (remaining, (children, _exit_contents)) = verify( - many_till( - parser_with_context!(standard_set_object)(&parser_context), - parser_with_context!(exit_matcher_parser)(&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), + |text| text.len() > 0, ), - |(children, _exit_contents)| !children.is_empty(), + confine_context(|i| { + all_consuming(many1(parser_with_context!(standard_set_object)( + &initial_context, + )))(i) + }), )(remaining)?; + let (remaining, _) = tag("]")(remaining)?; let (remaining, _trailing_whitespace) = @@ -104,7 +134,10 @@ fn inline_footnote<'b, 'g, 'r, 's>( )) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn footnote_reference_only<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -131,7 +164,10 @@ fn footnote_definition_end(starting_bracket_depth: BracketDepth) -> impl Context } } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(_context)) +)] fn _footnote_definition_end<'b, 'g, 'r, 's>( _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, diff --git a/src/parser/greater_block.rs b/src/parser/greater_block.rs index 3dd09d1..4d5e72d 100644 --- a/src/parser/greater_block.rs +++ b/src/parser/greater_block.rs @@ -44,7 +44,10 @@ use crate::types::QuoteBlock; use crate::types::SetSource; use crate::types::SpecialBlock; -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] pub(crate) fn greater_block<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -86,7 +89,10 @@ pub(crate) fn greater_block<'b, 'g, 'r, 's>( Ok((remaining, element)) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn center_block<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -110,7 +116,10 @@ fn center_block<'b, 'g, 'r, 's>( )) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn quote_block<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -156,7 +165,10 @@ fn special_block<'s>( } } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn _special_block<'c, 'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -185,7 +197,10 @@ fn _special_block<'c, 'b, 'g, 'r, 's>( )) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn greater_block_body<'c, 'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -254,7 +269,10 @@ fn greater_block_end<'c>(name: &'c str) -> impl ContextMatcher + 'c { move |context, input: OrgSource<'_>| _greater_block_end(context, input, name) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(_context)) +)] fn _greater_block_end<'b, 'g, 'r, 's, 'c>( _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, diff --git a/src/parser/headline.rs b/src/parser/headline.rs index f59bde2..b25af61 100644 --- a/src/parser/headline.rs +++ b/src/parser/headline.rs @@ -50,7 +50,10 @@ pub(crate) const fn heading( move |context, input: OrgSource<'_>| _heading(context, input, parent_level) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn _heading<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -134,7 +137,10 @@ struct PreHeadline<'s> { is_footnote_section: bool, } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn headline<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -211,7 +217,10 @@ fn headline<'b, 'g, 'r, 's>( )) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(_context)) +)] fn headline_title_end<'b, 'g, 'r, 's>( _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -233,7 +242,10 @@ fn single_tag<'r, 's>(input: OrgSource<'s>) -> Res, OrgSource<'s>> })))(input) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn heading_keyword<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -293,7 +305,10 @@ fn priority_cookie<'s>(input: OrgSource<'s>) -> Res, PriorityCooki Ok((remaining, cookie)) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn headline_level<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, diff --git a/src/parser/horizontal_rule.rs b/src/parser/horizontal_rule.rs index ece5205..6cbed2b 100644 --- a/src/parser/horizontal_rule.rs +++ b/src/parser/horizontal_rule.rs @@ -19,7 +19,7 @@ use crate::error::Res; use crate::parser::util::start_of_line; use crate::types::HorizontalRule; -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug", skip(context)))] pub(crate) fn horizontal_rule<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, diff --git a/src/parser/in_buffer_settings.rs b/src/parser/in_buffer_settings.rs index 60ff54b..3fbc4b1 100644 --- a/src/parser/in_buffer_settings.rs +++ b/src/parser/in_buffer_settings.rs @@ -84,7 +84,7 @@ fn in_buffer_settings_key<'s>(input: OrgSource<'s>) -> Res, OrgSou ))(input) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr(feature = "tracing", tracing::instrument(level = "debug"))] pub(crate) fn apply_in_buffer_settings<'g, 's, 'sf>( keywords: Vec>, original_settings: &'g GlobalSettings<'g, 's>, diff --git a/src/parser/inline_babel_call.rs b/src/parser/inline_babel_call.rs index ce5c97c..41abea6 100644 --- a/src/parser/inline_babel_call.rs +++ b/src/parser/inline_babel_call.rs @@ -25,7 +25,10 @@ use crate::parser::util::exit_matcher_parser; use crate::parser::util::get_consumed; use crate::types::InlineBabelCall; -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] pub(crate) fn inline_babel_call<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -46,7 +49,10 @@ pub(crate) fn inline_babel_call<'b, 'g, 'r, 's>( )) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn name<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -63,7 +69,10 @@ fn name<'b, 'g, 'r, 's>( Ok((remaining, name)) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(_context)) +)] fn name_end<'b, 'g, 'r, 's>( _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -71,7 +80,10 @@ fn name_end<'b, 'g, 'r, 's>( recognize(one_of("[("))(input) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn header<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -97,7 +109,10 @@ fn header_end(starting_bracket_depth: BracketDepth) -> impl ContextMatcher { move |context, input: OrgSource<'_>| _header_end(context, input, starting_bracket_depth) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(_context)) +)] fn _header_end<'b, 'g, 'r, 's>( _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -117,7 +132,10 @@ fn _header_end<'b, 'g, 'r, 's>( alt((tag("]"), line_ending))(input) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn argument<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -143,7 +161,10 @@ fn argument_end(starting_parenthesis_depth: BracketDepth) -> impl ContextMatcher move |context, input: OrgSource<'_>| _argument_end(context, input, starting_parenthesis_depth) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(_context)) +)] fn _argument_end<'b, 'g, 'r, 's>( _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, diff --git a/src/parser/inline_source_block.rs b/src/parser/inline_source_block.rs index 6e5cd5f..cf41e2e 100644 --- a/src/parser/inline_source_block.rs +++ b/src/parser/inline_source_block.rs @@ -27,7 +27,10 @@ use crate::parser::util::exit_matcher_parser; use crate::parser::util::get_consumed; use crate::types::InlineSourceBlock; -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] pub(crate) fn inline_source_block<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -47,7 +50,10 @@ pub(crate) fn inline_source_block<'b, 'g, 'r, 's>( )) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn lang<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -64,7 +70,10 @@ fn lang<'b, 'g, 'r, 's>( Ok((remaining, lang)) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(_context)) +)] fn lang_end<'b, 'g, 'r, 's>( _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -72,7 +81,10 @@ fn lang_end<'b, 'g, 'r, 's>( recognize(one_of("[{"))(input) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn header<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -98,7 +110,10 @@ fn header_end(starting_bracket_depth: BracketDepth) -> impl ContextMatcher { move |context, input: OrgSource<'_>| _header_end(context, input, starting_bracket_depth) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(_context)) +)] fn _header_end<'b, 'g, 'r, 's>( _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -118,7 +133,10 @@ fn _header_end<'b, 'g, 'r, 's>( alt((tag("]"), line_ending))(input) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn body<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -154,7 +172,10 @@ fn body_end(starting_brace_depth: BracketDepth) -> impl ContextMatcher { move |context, input: OrgSource<'_>| _body_end(context, input, starting_brace_depth) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(_context)) +)] fn _body_end<'b, 'g, 'r, 's>( _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, diff --git a/src/parser/keyword.rs b/src/parser/keyword.rs index 7c4dfc5..70bf4ed 100644 --- a/src/parser/keyword.rs +++ b/src/parser/keyword.rs @@ -89,7 +89,10 @@ fn _filtered_keyword<'s, F: Matcher>( )) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] pub(crate) fn keyword<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -104,7 +107,10 @@ pub(crate) fn keyword<'b, 'g, 'r, 's>( Ok((remaining, kw)) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] pub(crate) fn affiliated_keyword_as_regular_keyword<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -122,7 +128,10 @@ pub(crate) fn affiliated_keyword<'s>(input: OrgSource<'s>) -> Res, filtered_keyword(affiliated_key)(input) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(_context)) +)] pub(crate) fn table_formula_keyword<'b, 'g, 'r, 's>( _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, diff --git a/src/parser/latex_environment.rs b/src/parser/latex_environment.rs index 3167164..692d046 100644 --- a/src/parser/latex_environment.rs +++ b/src/parser/latex_environment.rs @@ -28,7 +28,10 @@ use crate::parser::util::exit_matcher_parser; use crate::parser::util::start_of_line; use crate::types::LatexEnvironment; -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] pub(crate) fn latex_environment<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -81,7 +84,7 @@ fn contents(end_matcher: F) -> impl ContextMatcher { #[cfg_attr( feature = "tracing", - tracing::instrument(ret, level = "debug", skip(end_matcher)) + tracing::instrument(ret, level = "debug", skip(context, end_matcher)) )] fn _contents<'b, 'g, 'r, 's, F: ContextMatcher>( end_matcher: F, @@ -106,7 +109,10 @@ fn latex_environment_end(current_name: &str) -> impl ContextMatcher { } } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(_context)) +)] fn _latex_environment_end<'b, 'g, 'r, 's, 'c>( _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, diff --git a/src/parser/latex_fragment.rs b/src/parser/latex_fragment.rs index 96c99af..9b1c679 100644 --- a/src/parser/latex_fragment.rs +++ b/src/parser/latex_fragment.rs @@ -23,7 +23,10 @@ use crate::parser::util::exit_matcher_parser; use crate::parser::util::get_consumed; use crate::types::LatexFragment; -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] pub(crate) fn latex_fragment<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -49,7 +52,10 @@ pub(crate) fn latex_fragment<'b, 'g, 'r, 's>( )) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn raw_latex_fragment<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -62,7 +68,10 @@ fn raw_latex_fragment<'b, 'g, 'r, 's>( Ok((remaining, source)) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(_context)) +)] fn name<'b, 'g, 'r, 's>( _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -70,7 +79,10 @@ fn name<'b, 'g, 'r, 's>( alpha1(input) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn brackets<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -102,7 +114,10 @@ fn brackets<'b, 'g, 'r, 's>( Ok((remaining, body)) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn escaped_parenthesis_fragment<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -121,7 +136,10 @@ fn escaped_parenthesis_fragment<'b, 'g, 'r, 's>( Ok((remaining, source)) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn escaped_bracket_fragment<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -140,7 +158,10 @@ fn escaped_bracket_fragment<'b, 'g, 'r, 's>( Ok((remaining, source)) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn double_dollar_fragment<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -160,7 +181,10 @@ fn double_dollar_fragment<'b, 'g, 'r, 's>( Ok((remaining, source)) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn dollar_char_fragment<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -175,7 +199,10 @@ fn dollar_char_fragment<'b, 'g, 'r, 's>( Ok((remaining, source)) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(_context)) +)] fn pre<'b, 'g, 'r, 's>( _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -189,7 +216,10 @@ fn pre<'b, 'g, 'r, 's>( Ok((input, ())) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(_context)) +)] fn post<'b, 'g, 'r, 's>( _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -201,7 +231,10 @@ fn post<'b, 'g, 'r, 's>( Ok((remaining, ())) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn bordered_dollar_fragment<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -227,7 +260,10 @@ fn bordered_dollar_fragment<'b, 'g, 'r, 's>( Ok((remaining, source)) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(_context)) +)] fn open_border<'b, 'g, 'r, 's>( _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -235,7 +271,10 @@ fn open_border<'b, 'g, 'r, 's>( recognize(verify(none_of(".,;$"), |c| !c.is_whitespace()))(input) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(_context)) +)] fn close_border<'b, 'g, 'r, 's>( _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, diff --git a/src/parser/lesser_block.rs b/src/parser/lesser_block.rs index e810c73..b849082 100644 --- a/src/parser/lesser_block.rs +++ b/src/parser/lesser_block.rs @@ -48,7 +48,10 @@ use crate::types::SrcBlock; use crate::types::SwitchNumberLines; use crate::types::VerseBlock; -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] pub(crate) fn verse_block<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -106,7 +109,10 @@ pub(crate) fn verse_block<'b, 'g, 'r, 's>( )) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] pub(crate) fn comment_block<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -144,7 +150,10 @@ pub(crate) fn comment_block<'b, 'g, 'r, 's>( )) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] pub(crate) fn example_block<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -207,7 +216,10 @@ pub(crate) fn example_block<'b, 'g, 'r, 's>( )) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] pub(crate) fn export_block<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -253,7 +265,10 @@ pub(crate) fn export_block<'b, 'g, 'r, 's>( )) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] pub(crate) fn src_block<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -338,7 +353,10 @@ fn lesser_block_end<'c>(current_name: &'c str) -> impl ContextMatcher + 'c { move |context, input: OrgSource<'_>| _lesser_block_end(context, input, current_name) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(_context)) +)] fn _lesser_block_end<'b, 'g, 'r, 's, 'c>( _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -364,7 +382,10 @@ const fn lesser_block_begin<'c>(current_name: &'c str) -> impl ContextMatcher + move |context, input: OrgSource<'_>| _lesser_block_begin(context, input, current_name) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(_context)) +)] fn _lesser_block_begin<'b, 'g, 'r, 's, 'c>( _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -594,7 +615,10 @@ fn switch_word<'s>(input: OrgSource<'s>) -> Res, OrgSource<'s>> { ))(input) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] pub(crate) fn content<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, diff --git a/src/parser/line_break.rs b/src/parser/line_break.rs index 30c8eca..b93c3c7 100644 --- a/src/parser/line_break.rs +++ b/src/parser/line_break.rs @@ -12,7 +12,10 @@ use crate::error::Res; use crate::parser::util::get_consumed; use crate::types::LineBreak; -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] pub(crate) fn line_break<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -30,7 +33,10 @@ pub(crate) fn line_break<'b, 'g, 'r, 's>( )) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(_context)) +)] fn pre<'b, 'g, 'r, 's>( _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, diff --git a/src/parser/object_parser.rs b/src/parser/object_parser.rs index f672855..98ae908 100644 --- a/src/parser/object_parser.rs +++ b/src/parser/object_parser.rs @@ -31,7 +31,7 @@ use crate::parser::text_markup::text_markup; use crate::parser::timestamp::timestamp; use crate::types::Object; -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug", skip(context)))] pub(crate) fn standard_set_object<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -46,7 +46,7 @@ pub(crate) fn standard_set_object<'b, 'g, 'r, 's>( Ok((remaining, object)) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug", skip(context)))] pub(crate) fn minimal_set_object<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -61,7 +61,7 @@ pub(crate) fn minimal_set_object<'b, 'g, 'r, 's>( Ok((remaining, object)) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug", skip(context)))] fn standard_set_object_sans_plain_text<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -118,7 +118,7 @@ fn standard_set_object_sans_plain_text<'b, 'g, 'r, 's>( Ok((remaining, object)) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug", skip(context)))] fn minimal_set_object_sans_plain_text<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -139,7 +139,7 @@ fn minimal_set_object_sans_plain_text<'b, 'g, 'r, 's>( Ok((remaining, object)) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug", skip(context)))] pub(crate) fn detect_standard_set_object_sans_plain_text<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -156,7 +156,7 @@ pub(crate) fn detect_standard_set_object_sans_plain_text<'b, 'g, 'r, 's>( )))); } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug", skip(context)))] fn detect_minimal_set_object_sans_plain_text<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -173,7 +173,7 @@ fn detect_minimal_set_object_sans_plain_text<'b, 'g, 'r, 's>( )))); } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug", skip(context)))] pub(crate) fn regular_link_description_set_object<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -191,7 +191,7 @@ pub(crate) fn regular_link_description_set_object<'b, 'g, 'r, 's>( Ok((remaining, object)) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug", skip(context)))] fn regular_link_description_set_object_sans_plain_text<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -220,7 +220,7 @@ fn regular_link_description_set_object_sans_plain_text<'b, 'g, 'r, 's>( Ok((remaining, object)) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug", skip(context)))] fn detect_regular_link_description_set_object_sans_plain_text<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -237,7 +237,7 @@ fn detect_regular_link_description_set_object_sans_plain_text<'b, 'g, 'r, 's>( )))); } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug", skip(context)))] pub(crate) fn table_cell_set_object<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -252,7 +252,7 @@ pub(crate) fn table_cell_set_object<'b, 'g, 'r, 's>( Ok((remaining, object)) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug", skip(context)))] fn table_cell_set_object_sans_plain_text<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -286,7 +286,7 @@ fn table_cell_set_object_sans_plain_text<'b, 'g, 'r, 's>( Ok((remaining, object)) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug", skip(context)))] fn detect_table_cell_set_object_sans_plain_text<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, diff --git a/src/parser/org_macro.rs b/src/parser/org_macro.rs index 9ead92e..d86745f 100644 --- a/src/parser/org_macro.rs +++ b/src/parser/org_macro.rs @@ -19,7 +19,10 @@ use crate::parser::util::exit_matcher_parser; use crate::parser::util::get_consumed; use crate::types::OrgMacro; -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] pub(crate) fn org_macro<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -48,7 +51,10 @@ pub(crate) fn org_macro<'b, 'g, 'r, 's>( )) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(_context)) +)] fn org_macro_name<'b, 'g, 'r, 's>( _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -61,7 +67,10 @@ fn org_macro_name<'b, 'g, 'r, 's>( Ok((remaining, source)) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn org_macro_args<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -74,7 +83,10 @@ fn org_macro_args<'b, 'g, 'r, 's>( Ok((remaining, args)) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn org_macro_arg<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, diff --git a/src/parser/paragraph.rs b/src/parser/paragraph.rs index 746e23f..2a100a7 100644 --- a/src/parser/paragraph.rs +++ b/src/parser/paragraph.rs @@ -29,7 +29,7 @@ use crate::parser::util::exit_matcher_parser; use crate::parser::util::start_of_line; use crate::types::Paragraph; -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug", skip(context)))] pub(crate) fn paragraph<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -71,7 +71,7 @@ pub(crate) fn paragraph<'b, 'g, 'r, 's>( )) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug", skip(context)))] fn paragraph_end<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, diff --git a/src/parser/plain_link.rs b/src/parser/plain_link.rs index aa4f1a2..ce04d05 100644 --- a/src/parser/plain_link.rs +++ b/src/parser/plain_link.rs @@ -44,7 +44,10 @@ use crate::parser::util::WORD_CONSTITUENT_CHARACTERS; use crate::types::LinkType; use crate::types::PlainLink; -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] pub(crate) fn plain_link<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -77,7 +80,10 @@ struct PathPlain<'s> { application: Option<&'s str>, } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(_context)) +)] fn pre<'b, 'g, 'r, 's>( _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -97,7 +103,10 @@ fn pre<'b, 'g, 'r, 's>( Ok((input, ())) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(_context)) +)] fn post<'b, 'g, 'r, 's>( _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -106,7 +115,10 @@ fn post<'b, 'g, 'r, 's>( Ok((remaining, ())) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn parse_path_plain<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -167,7 +179,10 @@ pub(crate) fn parse_path_and_search_option_without_search_option<'s>( map(rest, |path| (path, None))(input) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn file_path_plain<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -207,7 +222,10 @@ fn file_path_plain<'b, 'g, 'r, 's>( )) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn protocol_path_plain<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -235,7 +253,10 @@ fn protocol_path_plain<'b, 'g, 'r, 's>( )) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] pub(crate) fn protocol<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -255,7 +276,10 @@ pub(crate) fn protocol<'b, 'g, 'r, 's>( )))) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn path_plain<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -284,7 +308,10 @@ fn path_plain_end( } } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn impl_path_plain_end<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -323,7 +350,10 @@ fn impl_path_plain_end<'b, 'g, 'r, 's>( )))) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn path_plain_no_parenthesis<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -351,7 +381,10 @@ fn path_plain_no_parenthesis_disallowed_character<'s>( }))(input) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn path_plain_parenthesis<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, diff --git a/src/parser/plain_list.rs b/src/parser/plain_list.rs index 7aee12a..5bf1171 100644 --- a/src/parser/plain_list.rs +++ b/src/parser/plain_list.rs @@ -50,7 +50,10 @@ use crate::types::PlainListItemCounter; use crate::types::PlainListItemPreBlank; use crate::types::PlainListType; -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] pub(crate) fn detect_plain_list<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -76,7 +79,10 @@ pub(crate) fn detect_plain_list<'b, 'g, 'r, 's>( )))); } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] pub(crate) fn plain_list<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -164,7 +170,10 @@ pub(crate) fn plain_list<'b, 'g, 'r, 's>( )) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn plain_list_item<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -294,7 +303,10 @@ enum BulletType { Unordered, } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn bullet<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -318,7 +330,10 @@ fn bullet<'b, 'g, 'r, 's>( Ok((remaining, (bullet_type, with_space))) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn counter<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -358,7 +373,10 @@ fn counter_set_value<'s>(input: OrgSource<'s>) -> Res, PlainListIt ))(input) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(_context)) +)] fn plain_list_end<'b, 'g, 'r, 's>( _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -380,7 +398,7 @@ const fn plain_list_item_end(indent_level: IndentationLevel) -> impl ContextMatc #[cfg_attr( feature = "tracing", - tracing::instrument(ret, level = "debug", skip(line_indented_lte_matcher)) + tracing::instrument(ret, level = "debug", skip(context, line_indented_lte_matcher)) )] fn _plain_list_item_end<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, @@ -398,7 +416,10 @@ const fn line_indented_lte(indent_level: IndentationLevel) -> impl ContextMatche move |context, input: OrgSource<'_>| _line_indented_lte(context, input, indent_level) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn _line_indented_lte<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -416,7 +437,10 @@ fn _line_indented_lte<'b, 'g, 'r, 's>( Ok(matched) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn item_tag<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -438,7 +462,10 @@ fn item_tag<'b, 'g, 'r, 's>( Ok((remaining, children)) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(_context)) +)] fn item_tag_end<'b, 'g, 'r, 's>( _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -461,7 +488,10 @@ fn item_tag_divider<'s>(input: OrgSource<'s>) -> Res, OrgSource<'s )))(input) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn item_tag_post_gap<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -494,7 +524,10 @@ fn item_checkbox<'s>(input: OrgSource<'s>) -> Res, (CheckboxType, ))(input) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn detect_contentless_item_contents<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, diff --git a/src/parser/plain_text.rs b/src/parser/plain_text.rs index 756d4c9..7287a7b 100644 --- a/src/parser/plain_text.rs +++ b/src/parser/plain_text.rs @@ -42,7 +42,7 @@ where #[cfg_attr( feature = "tracing", - tracing::instrument(ret, level = "debug", skip(end_condition)) + tracing::instrument(ret, level = "debug", skip(context, end_condition)) )] fn _plain_text<'b, 'g, 'r, 's, F>( end_condition: F, @@ -75,7 +75,10 @@ where } impl<'x> RematchObject<'x> for PlainText<'x> { - #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] + #[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(_context)) + )] fn rematch_object<'b, 'g, 'r, 's>( &'x self, _context: RefContext<'b, 'g, 'r, 's>, diff --git a/src/parser/planning.rs b/src/parser/planning.rs index 73b471d..d8f37b5 100644 --- a/src/parser/planning.rs +++ b/src/parser/planning.rs @@ -19,7 +19,7 @@ use crate::parser::util::start_of_line; use crate::types::Planning; use crate::types::Timestamp; -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug", skip(context)))] pub(crate) fn planning<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -70,7 +70,7 @@ enum PlanningTimestampType { Closed, } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug", skip(context)))] fn planning_parameter<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, diff --git a/src/parser/property_drawer.rs b/src/parser/property_drawer.rs index 99f0177..13ee298 100644 --- a/src/parser/property_drawer.rs +++ b/src/parser/property_drawer.rs @@ -30,7 +30,10 @@ use crate::parser::util::start_of_line; use crate::types::NodeProperty; use crate::types::PropertyDrawer; -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] pub(crate) fn property_drawer<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -82,7 +85,10 @@ pub(crate) fn property_drawer<'b, 'g, 'r, 's>( )) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(_context)) +)] fn property_drawer_end<'b, 'g, 'r, 's>( _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -96,7 +102,10 @@ fn property_drawer_end<'b, 'g, 'r, 's>( )))(input) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn node_property<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -141,7 +150,10 @@ fn node_property<'b, 'g, 'r, 's>( } } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn node_property_name<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -166,7 +178,10 @@ fn node_property_name<'b, 'g, 'r, 's>( Ok((remaining, name)) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(_context)) +)] fn node_property_name_end<'b, 'g, 'r, 's>( _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, diff --git a/src/parser/radio_link.rs b/src/parser/radio_link.rs index c25ec3c..4dde382 100644 --- a/src/parser/radio_link.rs +++ b/src/parser/radio_link.rs @@ -2,19 +2,23 @@ use nom::branch::alt; use nom::bytes::complete::tag; use nom::character::complete::line_ending; use nom::character::complete::space0; +use nom::combinator::all_consuming; use nom::combinator::consumed; -use nom::combinator::map; +use nom::combinator::map_parser; use nom::combinator::verify; -use nom::multi::many_till; +use nom::multi::many1; use super::object_parser::minimal_set_object; use super::org_source::OrgSource; -use super::util::exit_matcher_parser; +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; @@ -24,7 +28,10 @@ use crate::types::Object; use crate::types::RadioLink; use crate::types::RadioTarget; -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] pub(crate) fn radio_link<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -50,7 +57,10 @@ pub(crate) fn radio_link<'b, 'g, 'r, 's>( )))) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] pub(crate) fn rematch_target<'x, 'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, target: &'x Vec>, @@ -97,31 +107,33 @@ pub(crate) fn rematch_target<'x, 'b, 'g, 'r, 's>( Ok((remaining, new_matches)) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] pub(crate) fn radio_target<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, RadioTarget<'s>> { let (remaining, _opening) = tag("<<<")(input)?; - let contexts = [ - ContextElement::ExitMatcherNode(ExitMatcherNode { - class: ExitClass::Gamma, - exit_matcher: &radio_target_end, - }), - ContextElement::StartTextSection(remaining), - ]; - let parser_context = context.with_additional_node(&contexts[0]); - let parser_context = parser_context.with_additional_node(&contexts[1]); + let parser_context = ContextElement::ExitMatcherNode(ExitMatcherNode { + class: ExitClass::Gamma, + 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(verify( - map( - many_till( - parser_with_context!(minimal_set_object)(&parser_context), - parser_with_context!(exit_matcher_parser)(&parser_context), - ), - |(children, _)| children, + let (remaining, (raw_value, children)) = consumed(map_parser( + verify( + parser_with_context!(text_until_exit)(&parser_context), + |text| text.len() > 0, ), - |children: &Vec<_>| !children.is_empty(), + confine_context(|i| { + all_consuming(many1(parser_with_context!(minimal_set_object)( + &initial_context, + )))(i) + }), ))(remaining)?; let (remaining, _closing) = tag(">>>")(remaining)?; @@ -138,7 +150,10 @@ pub(crate) fn radio_target<'b, 'g, 'r, 's>( )) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(_context)) +)] fn radio_target_end<'b, 'g, 'r, 's>( _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, diff --git a/src/parser/regular_link.rs b/src/parser/regular_link.rs index ce9ce37..dd7a054 100644 --- a/src/parser/regular_link.rs +++ b/src/parser/regular_link.rs @@ -8,6 +8,7 @@ use nom::bytes::complete::take; use nom::bytes::complete::take_till1; use nom::bytes::complete::take_until; use nom::character::complete::anychar; +use nom::combinator::all_consuming; use nom::combinator::consumed; use nom::combinator::eof; use nom::combinator::flat_map; @@ -18,6 +19,7 @@ use nom::combinator::peek; use nom::combinator::recognize; use nom::combinator::rest; use nom::combinator::verify; +use nom::multi::many1; use nom::multi::many1_count; use nom::multi::many_till; use nom::sequence::tuple; @@ -28,15 +30,17 @@ use super::org_source::BracketDepth; use super::org_source::OrgSource; use super::plain_link::parse_file_and_application; use super::plain_link::protocol; -use super::util::exit_matcher_parser; +use super::util::confine_context; 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; @@ -45,7 +49,10 @@ use crate::types::LinkType; use crate::types::Object; use crate::types::RegularLink; -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] pub(crate) fn regular_link<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -56,7 +63,10 @@ pub(crate) fn regular_link<'b, 'g, 'r, 's>( ))(input) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn regular_link_without_description<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -81,7 +91,10 @@ fn regular_link_without_description<'b, 'g, 'r, 's>( )) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn regular_link_with_description<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -117,7 +130,10 @@ struct PathReg<'s> { application: Option>, } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn pathreg<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -136,7 +152,10 @@ fn pathreg<'b, 'g, 'r, 's>( Ok((remaining, path)) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn parse_path_reg<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -192,7 +211,10 @@ enum ParserState { Percent, } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn apply_link_templates<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -252,7 +274,10 @@ fn apply_link_templates<'b, 'g, 'r, 's>( Some(ret) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn file_path_reg<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -355,7 +380,10 @@ fn code_ref_path_reg<'s>(input: OrgSource<'s>) -> Res, PathReg<'s> )) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn protocol_path_reg<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -392,32 +420,41 @@ fn fuzzy_path_reg<'s>(input: OrgSource<'s>) -> Res, PathReg<'s>> { )) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn description<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, Vec>> { - let contexts = [ - ContextElement::ExitMatcherNode(ExitMatcherNode { - class: ExitClass::Beta, - exit_matcher: &description_end, - }), - ContextElement::StartTextSection(input), - ]; - let parser_context = context.with_additional_node(&contexts[0]); - let parser_context = parser_context.with_additional_node(&contexts[1]); - let (remaining, (children, _exit_contents)) = verify( - many_till( - parser_with_context!(regular_link_description_set_object)(&parser_context), - parser_with_context!(exit_matcher_parser)(&parser_context), + let parser_context = ContextElement::ExitMatcherNode(ExitMatcherNode { + class: ExitClass::Beta, + 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), + |text| text.len() > 0, ), - |(children, _exit_contents)| !children.is_empty(), + confine_context(|i| { + all_consuming(many1(parser_with_context!( + regular_link_description_set_object + )(&initial_context)))(i) + }), )(input)?; Ok((remaining, children)) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(_context)) +)] fn description_end<'b, 'g, 'r, 's>( _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -439,7 +476,10 @@ fn path_reg_end( } } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(_context)) +)] fn impl_path_reg_end<'b, 'g, 'r, 's>( _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, diff --git a/src/parser/section.rs b/src/parser/section.rs index d85633f..ef58719 100644 --- a/src/parser/section.rs +++ b/src/parser/section.rs @@ -24,7 +24,10 @@ use crate::parser::util::maybe_consume_trailing_whitespace_if_not_exiting; use crate::types::Element; use crate::types::Section; -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] pub(crate) fn zeroth_section<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -82,7 +85,10 @@ pub(crate) fn zeroth_section<'b, 'g, 'r, 's>( )) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] pub(crate) fn section<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, mut input: OrgSource<'s>, @@ -135,7 +141,10 @@ pub(crate) fn section<'b, 'g, 'r, 's>( )) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(_context)) +)] fn section_end<'b, 'g, 'r, 's>( _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, diff --git a/src/parser/statistics_cookie.rs b/src/parser/statistics_cookie.rs index c2dd44e..ba578b1 100644 --- a/src/parser/statistics_cookie.rs +++ b/src/parser/statistics_cookie.rs @@ -12,7 +12,7 @@ use crate::context::RefContext; use crate::error::Res; use crate::types::StatisticsCookie; -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug", skip(context)))] pub(crate) fn statistics_cookie<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -23,7 +23,7 @@ pub(crate) fn statistics_cookie<'b, 'g, 'r, 's>( ))(input) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug", skip(context)))] fn percent_statistics_cookie<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -44,7 +44,7 @@ fn percent_statistics_cookie<'b, 'g, 'r, 's>( )) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug", skip(context)))] fn fraction_statistics_cookie<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, diff --git a/src/parser/subscript_and_superscript.rs b/src/parser/subscript_and_superscript.rs index c1b2829..5f8c324 100644 --- a/src/parser/subscript_and_superscript.rs +++ b/src/parser/subscript_and_superscript.rs @@ -46,7 +46,10 @@ pub(crate) fn detect_subscript_or_superscript<'s>(input: OrgSource<'s>) -> Res( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -66,7 +69,10 @@ pub(crate) fn subscript<'b, 'g, 'r, 's>( )) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] pub(crate) fn superscript<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -98,7 +104,10 @@ enum ScriptBody<'s> { WithBraces(Vec>), } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn script_body<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -120,7 +129,10 @@ fn script_body<'b, 'g, 'r, 's>( ))(input) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(_context)) +)] fn script_asterisk<'b, 'g, 'r, 's>( _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -128,7 +140,10 @@ fn script_asterisk<'b, 'g, 'r, 's>( tag("*")(input) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(_context)) +)] fn script_alphanum<'b, 'g, 'r, 's>( _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -157,7 +172,10 @@ fn end_script_alphanum_character<'s>(input: OrgSource<'s>) -> Res, Ok((remaining, final_char)) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn script_with_braces<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -185,7 +203,10 @@ fn script_with_braces_end(starting_brace_depth: BracketDepth) -> impl ContextMat } } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(_context)) +)] fn _script_with_braces_end<'b, 'g, 'r, 's>( _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -205,7 +226,10 @@ fn _script_with_braces_end<'b, 'g, 'r, 's>( tag("}")(input) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn script_with_parenthesis<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, diff --git a/src/parser/table.rs b/src/parser/table.rs index 695259f..ac0083d 100644 --- a/src/parser/table.rs +++ b/src/parser/table.rs @@ -36,7 +36,10 @@ use crate::types::TableRow; /// Parse an org-mode-style table /// /// This is not the table.el style. -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] pub(crate) fn org_mode_table<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -88,7 +91,10 @@ pub(crate) fn detect_table<'s>(input: OrgSource<'s>) -> Res, ()> { Ok((input, ())) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(_context)) +)] fn table_end<'b, 'g, 'r, 's>( _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -97,7 +103,10 @@ fn table_end<'b, 'g, 'r, 's>( recognize(tuple((space0, not(tag("|")))))(input) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn org_mode_table_row<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -108,7 +117,10 @@ fn org_mode_table_row<'b, 'g, 'r, 's>( ))(input) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(_context)) +)] fn org_mode_table_row_rule<'b, 'g, 'r, 's>( _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -125,7 +137,10 @@ fn org_mode_table_row_rule<'b, 'g, 'r, 's>( )) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn org_mode_table_row_regular<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -145,7 +160,10 @@ fn org_mode_table_row_regular<'b, 'g, 'r, 's>( )) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn org_mode_table_cell<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -178,7 +196,10 @@ fn org_mode_table_cell<'b, 'g, 'r, 's>( )) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(_context)) +)] fn org_mode_table_cell_end<'b, 'g, 'r, 's>( _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, diff --git a/src/parser/target.rs b/src/parser/target.rs index 29006c5..b73acd4 100644 --- a/src/parser/target.rs +++ b/src/parser/target.rs @@ -20,7 +20,10 @@ use crate::error::Res; use crate::parser::util::get_consumed; use crate::types::Target; -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] pub(crate) fn target<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -61,7 +64,10 @@ pub(crate) fn target<'b, 'g, 'r, 's>( )) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(_context)) +)] fn target_end<'b, 'g, 'r, 's>( _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, diff --git a/src/parser/text_markup.rs b/src/parser/text_markup.rs index 7bf7bf1..caa6b5f 100644 --- a/src/parser/text_markup.rs +++ b/src/parser/text_markup.rs @@ -1,7 +1,6 @@ use nom::branch::alt; use nom::bytes::complete::tag; use nom::character::complete::anychar; -use nom::character::complete::line_ending; use nom::character::complete::multispace1; use nom::character::complete::one_of; use nom::character::complete::space0; @@ -20,6 +19,7 @@ use super::org_source::OrgSource; use super::radio_link::RematchObject; use super::util::in_object_section; use super::util::maybe_consume_object_trailing_whitespace_if_not_exiting; +use super::util::org_line_ending; use super::util::start_of_line; use crate::context::parser_with_context; use crate::context::ContextElement; @@ -42,7 +42,10 @@ use crate::types::StrikeThrough; use crate::types::Underline; use crate::types::Verbatim; -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] pub(crate) fn text_markup<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -60,7 +63,10 @@ pub(crate) fn text_markup<'b, 'g, 'r, 's>( ))(input) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn bold<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -76,7 +82,10 @@ fn bold<'b, 'g, 'r, 's>( )) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn italic<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -92,7 +101,10 @@ fn italic<'b, 'g, 'r, 's>( )) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn underline<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -108,7 +120,10 @@ fn underline<'b, 'g, 'r, 's>( )) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn strike_through<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -124,7 +139,10 @@ fn strike_through<'b, 'g, 'r, 's>( )) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn verbatim<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -140,7 +158,10 @@ fn verbatim<'b, 'g, 'r, 's>( )) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn code<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -166,7 +187,10 @@ fn text_markup_object<'c>( move |context, input: OrgSource<'_>| _text_markup_object(context, input, marker_symbol) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn _text_markup_object<'b, 'g, 'r, 's, 'c>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -229,7 +253,10 @@ fn text_markup_string<'c>( move |context, input: OrgSource<'_>| _text_markup_string(context, input, marker_symbol) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn _text_markup_string<'b, 'g, 'r, 's, 'c>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -281,9 +308,12 @@ fn _text_markup_string<'b, 'g, 'r, 's, 'c>( Ok((remaining, contents)) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(_context)) +)] fn pre<'b, 'g, 'r, 's>( - context: RefContext<'b, 'g, 'r, 's>, + _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, ()> { if start_of_line(input).is_ok() { @@ -292,16 +322,6 @@ fn pre<'b, 'g, 'r, 's>( if preceded_by_whitespace(true)(input).is_ok() { return Ok((input, ())); } - let radio_target_start = context - .iter() - .find_map(|c| match c { - ContextElement::StartTextSection(text) => Some(text), - _ => None, - }) - .map(|text| text.get_byte_offset()); - if Some(input.get_byte_offset()) == radio_target_start { - return Ok((input, ())); - } let preceding_character = input.get_preceding_character(); match preceding_character { // If None, we are at the start of the file which is technically the beginning of a line. @@ -316,12 +336,16 @@ fn pre<'b, 'g, 'r, 's>( Ok((input, ())) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(_context)) +)] fn post<'b, 'g, 'r, 's>( _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, ()> { - let (remaining, _) = alt((recognize(one_of(" \r\n\t-.,;:!?')}[\"\\")), line_ending))(input)?; + let (remaining, _) = + alt((recognize(one_of(" \r\n\t-.,;:!?')}[\"\\")), org_line_ending))(input)?; Ok((remaining, ())) } @@ -334,7 +358,10 @@ fn text_markup_end<'c>( } } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn _text_markup_end<'b, 'g, 'r, 's, 'c>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -356,7 +383,10 @@ fn _text_markup_end<'b, 'g, 'r, 's, 'c>( } impl<'x> RematchObject<'x> for Bold<'x> { - #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] + #[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(_context)) + )] fn rematch_object<'b, 'g, 'r, 's>( &'x self, _context: RefContext<'b, 'g, 'r, 's>, @@ -376,7 +406,10 @@ impl<'x> RematchObject<'x> for Bold<'x> { } impl<'x> RematchObject<'x> for Italic<'x> { - #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] + #[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(_context)) + )] fn rematch_object<'b, 'g, 'r, 's>( &'x self, _context: RefContext<'b, 'g, 'r, 's>, @@ -396,7 +429,10 @@ impl<'x> RematchObject<'x> for Italic<'x> { } impl<'x> RematchObject<'x> for Underline<'x> { - #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] + #[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(_context)) + )] fn rematch_object<'b, 'g, 'r, 's>( &'x self, _context: RefContext<'b, 'g, 'r, 's>, @@ -416,7 +452,10 @@ impl<'x> RematchObject<'x> for Underline<'x> { } impl<'x> RematchObject<'x> for StrikeThrough<'x> { - #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] + #[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(_context)) + )] fn rematch_object<'b, 'g, 'r, 's>( &'x self, _context: RefContext<'b, 'g, 'r, 's>, @@ -435,7 +474,10 @@ impl<'x> RematchObject<'x> for StrikeThrough<'x> { } } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn _rematch_text_markup_object<'b, 'g, 'r, 's, 'x>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, diff --git a/src/parser/timestamp.rs b/src/parser/timestamp.rs index dd666f2..e70e672 100644 --- a/src/parser/timestamp.rs +++ b/src/parser/timestamp.rs @@ -37,7 +37,10 @@ use crate::types::WarningDelay; use crate::types::WarningDelayType; use crate::types::Year; -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] pub(crate) fn timestamp<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -55,7 +58,10 @@ pub(crate) fn timestamp<'b, 'g, 'r, 's>( ))(input) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn diary_timestamp<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -83,7 +89,10 @@ fn diary_timestamp<'b, 'g, 'r, 's>( )) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn sexp<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -105,7 +114,10 @@ fn sexp<'b, 'g, 'r, 's>( Ok((remaining, body)) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(_context)) +)] fn sexp_end<'b, 'g, 'r, 's>( _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -113,7 +125,10 @@ fn sexp_end<'b, 'g, 'r, 's>( alt((tag(")>"), recognize(one_of(">\n"))))(input) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn active_timestamp<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -164,7 +179,10 @@ fn active_timestamp<'b, 'g, 'r, 's>( )) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] pub(crate) fn inactive_timestamp<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -215,7 +233,10 @@ pub(crate) fn inactive_timestamp<'b, 'g, 'r, 's>( )) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn active_date_range_timestamp<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -247,7 +268,10 @@ fn active_date_range_timestamp<'b, 'g, 'r, 's>( )) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn active_time_range_timestamp<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -298,7 +322,10 @@ fn active_time_range_timestamp<'b, 'g, 'r, 's>( )) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] pub(crate) fn inactive_date_range_timestamp<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -331,7 +358,10 @@ pub(crate) fn inactive_date_range_timestamp<'b, 'g, 'r, 's>( )) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] pub(crate) fn inactive_time_range_timestamp<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -382,7 +412,10 @@ pub(crate) fn inactive_time_range_timestamp<'b, 'g, 'r, 's>( )) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn date<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -415,7 +448,10 @@ fn date<'b, 'g, 'r, 's>( Ok((remaining, date)) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn dayname<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -437,7 +473,10 @@ fn dayname<'b, 'g, 'r, 's>( Ok((remaining, body)) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(_context)) +)] fn dayname_end<'b, 'g, 'r, 's>( _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -454,7 +493,10 @@ const fn time<'c>( move |context, input| _time(context, input, allow_rest) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn _time<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -482,7 +524,10 @@ fn _time<'b, 'g, 'r, 's>( Ok((remaining, time)) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn time_rest<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -495,7 +540,10 @@ fn time_rest<'b, 'g, 'r, 's>( Ok((remaining, body)) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn active_time_rest_end<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -510,7 +558,10 @@ fn active_time_rest_end<'b, 'g, 'r, 's>( ))(input) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn inactive_time_rest_end<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -525,7 +576,10 @@ fn inactive_time_rest_end<'b, 'g, 'r, 's>( ))(input) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] fn time_range_rest_end<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -539,7 +593,10 @@ fn time_range_rest_end<'b, 'g, 'r, 's>( exit_contents } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(_context)) +)] fn repeater<'b, 'g, 'r, 's>( _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -574,7 +631,10 @@ fn repeater<'b, 'g, 'r, 's>( )) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(_context)) +)] fn warning_delay<'b, 'g, 'r, 's>( _context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, diff --git a/src/parser/util.rs b/src/parser/util.rs index 5770de4..b3d05d6 100644 --- a/src/parser/util.rs +++ b/src/parser/util.rs @@ -1,3 +1,5 @@ +use std::fmt::Debug; + use nom::branch::alt; use nom::character::complete::anychar; use nom::character::complete::line_ending; @@ -89,7 +91,10 @@ fn element_trailing_whitespace<'s>(input: OrgSource<'s>) -> Res, O alt((eof, recognize(many0(blank_line))))(input) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] pub(crate) fn maybe_consume_object_trailing_whitespace_if_not_exiting<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -105,7 +110,10 @@ pub(crate) fn maybe_consume_object_trailing_whitespace_if_not_exiting<'b, 'g, 'r Ok((remaining, None)) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] pub(crate) fn maybe_consume_trailing_whitespace_if_not_exiting<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -118,7 +126,10 @@ pub(crate) fn maybe_consume_trailing_whitespace_if_not_exiting<'b, 'g, 'r, 's>( } } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] pub(crate) fn maybe_consume_trailing_whitespace<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -175,7 +186,10 @@ pub(crate) fn non_whitespace_character(input: OrgSource<'_>) -> Res( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -183,7 +197,10 @@ pub(crate) fn exit_matcher_parser<'b, 'g, 'r, 's>( peek(|i| context.check_exit_matcher(i))(input) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(context)) +)] pub(crate) fn text_until_exit<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, @@ -301,3 +318,28 @@ pub(crate) fn get_has_affiliated_keyword<'b, 'g, 'r, 's>( } None } + +/// Reset the input OrgSource as if it was starting a fresh document. +/// +/// This is important for making start-of-document, end-of-document, and other context-dependent tests succeed. +pub(crate) fn confine_context<'s, O: Debug, I: Fn(OrgSource<'s>) -> Res, O>>( + inner: I, +) -> impl Fn(OrgSource<'s>) -> Res, O> { + move |input| impl_confine_context(input, &inner) +} + +/// Reset the input OrgSource as if it was starting a fresh document. +/// +/// This is important for making start-of-document, end-of-document, and other context-dependent tests succeed. +#[cfg_attr( + feature = "tracing", + tracing::instrument(ret, level = "debug", skip(inner)) +)] +fn impl_confine_context<'s, O: Debug, I: Fn(OrgSource<'s>) -> Res, O>>( + input: OrgSource<'s>, + inner: I, +) -> Res, O> { + let raw_str = Into::<&str>::into(input); + let back_to_org_source = Into::>::into(raw_str); + inner(back_to_org_source) +} diff --git a/src/types/object.rs b/src/types/object.rs index f8b88d9..9018b40 100644 --- a/src/types/object.rs +++ b/src/types/object.rs @@ -200,11 +200,18 @@ pub struct FootnoteReference<'s> { #[derive(Debug, PartialEq)] pub struct Citation<'s> { pub source: &'s str, + pub style: Option<&'s str>, + pub prefix: Vec>, + pub suffix: Vec>, + pub children: Vec>, } #[derive(Debug, PartialEq)] pub struct CitationReference<'s> { pub source: &'s str, + pub key: &'s str, + pub prefix: Vec>, + pub suffix: Vec>, } #[derive(Debug, PartialEq)]