From 343af41f78de01c53b653d43e09107c7b5306ceb Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Thu, 5 Oct 2023 16:27:36 -0400 Subject: [PATCH 1/6] Separate babel call out to its own parser. --- src/compare/diff.rs | 1 + src/parser/babel_call.rs | 59 ++++++++++++++++++++++++++++++++++++ src/parser/element_parser.rs | 4 +-- src/parser/keyword.rs | 24 --------------- src/parser/mod.rs | 1 + src/types/lesser_element.rs | 1 - 6 files changed, 63 insertions(+), 27 deletions(-) create mode 100644 src/parser/babel_call.rs diff --git a/src/compare/diff.rs b/src/compare/diff.rs index 2e6f3042..7f766397 100644 --- a/src/compare/diff.rs +++ b/src/compare/diff.rs @@ -2416,6 +2416,7 @@ fn compare_babel_call<'b, 's>( )); } + // Compare value let value = unquote( get_property(emacs, ":value")? .ok_or("Emacs keywords should have a :value")? diff --git a/src/parser/babel_call.rs b/src/parser/babel_call.rs new file mode 100644 index 00000000..09613328 --- /dev/null +++ b/src/parser/babel_call.rs @@ -0,0 +1,59 @@ +use nom::bytes::complete::tag; +use nom::bytes::complete::tag_no_case; +use nom::character::complete::anychar; +use nom::character::complete::space0; +use nom::combinator::consumed; +use nom::combinator::peek; +use nom::combinator::recognize; +use nom::multi::many0; +use nom::multi::many_till; +use nom::sequence::tuple; +use nom::InputTake; + +use super::keyword::affiliated_keyword; +use super::util::get_name; +use super::OrgSource; +use crate::context::RefContext; +use crate::error::Res; +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"))] +pub(crate) fn babel_call<'b, 'g, 'r, 's>( + _context: RefContext<'b, 'g, 'r, 's>, + input: OrgSource<'s>, +) -> Res, BabelCall<'s>> { + let (input, affiliated_keywords) = many0(affiliated_keyword)(input)?; + + let (remaining, (consumed_input, (_, _, parsed_key, _))) = + consumed(tuple((space0, tag("#+"), tag_no_case("call"), tag(":"))))(input)?; + + if let Ok((remaining, (_, line_break))) = tuple((space0, org_line_ending))(remaining) { + let source = get_consumed(input, remaining); + return Ok(( + remaining, + BabelCall { + source: Into::<&str>::into(source), + name: get_name(&affiliated_keywords), + value: Into::<&str>::into(line_break.take(0)), + }, + )); + } + + let (remaining, _ws) = space0(remaining)?; + let (remaining, parsed_value) = + recognize(many_till(anychar, peek(tuple((space0, org_line_ending)))))(remaining)?; + let (remaining, _ws) = tuple((space0, org_line_ending))(remaining)?; + + let source = get_consumed(input, remaining); + + Ok(( + remaining, + BabelCall { + source: Into::<&str>::into(source), + name: get_name(&affiliated_keywords), + value: Into::<&str>::into(parsed_value), + }, + )) +} diff --git a/src/parser/element_parser.rs b/src/parser/element_parser.rs index 81dc435c..b4168319 100644 --- a/src/parser/element_parser.rs +++ b/src/parser/element_parser.rs @@ -6,6 +6,7 @@ use nom::sequence::tuple; #[cfg(feature = "tracing")] use tracing::span; +use super::babel_call::babel_call; use super::clock::clock; use super::comment::comment; use super::comment::detect_comment; @@ -20,7 +21,6 @@ use super::footnote_definition::footnote_definition; use super::greater_block::greater_block; use super::horizontal_rule::horizontal_rule; use super::keyword::affiliated_keyword; -use super::keyword::babel_call_keyword; use super::keyword::keyword; use super::latex_environment::latex_environment; use super::lesser_block::comment_block; @@ -76,7 +76,7 @@ fn _element<'b, 'g, 'r, 's>( let fixed_width_area_matcher = parser_with_context!(fixed_width_area)(context); let horizontal_rule_matcher = parser_with_context!(horizontal_rule)(context); let keyword_matcher = parser_with_context!(keyword)(context); - let babel_keyword_matcher = parser_with_context!(babel_call_keyword)(context); + let babel_keyword_matcher = parser_with_context!(babel_call)(context); let paragraph_matcher = parser_with_context!(paragraph)(context); let latex_environment_matcher = parser_with_context!(latex_environment)(context); diff --git a/src/parser/keyword.rs b/src/parser/keyword.rs index 34739bcd..19aea565 100644 --- a/src/parser/keyword.rs +++ b/src/parser/keyword.rs @@ -26,7 +26,6 @@ use crate::error::CustomError; use crate::error::MyError; use crate::error::Res; use crate::parser::util::start_of_line; -use crate::types::BabelCall; use crate::types::Keyword; const ORG_ELEMENT_AFFILIATED_KEYWORDS: [&'static str; 13] = [ @@ -104,29 +103,6 @@ pub(crate) fn affiliated_keyword<'s>(input: OrgSource<'s>) -> Res, filtered_keyword(affiliated_key)(input) } -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -pub(crate) fn babel_call_keyword<'b, 'g, 'r, 's>( - _context: RefContext<'b, 'g, 'r, 's>, - input: OrgSource<'s>, -) -> Res, BabelCall<'s>> { - let (input, affiliated_keywords) = many0(affiliated_keyword)(input)?; - let (remaining, kw) = filtered_keyword(babel_call_key)(input)?; - Ok(( - remaining, - BabelCall { - source: kw.source, - name: get_name(&affiliated_keywords), - key: kw.key, - value: kw.value, - }, - )) -} - -#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn babel_call_key<'s>(input: OrgSource<'s>) -> Res, OrgSource<'s>> { - tag_no_case("call")(input) -} - #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub(crate) fn table_formula_keyword<'b, 'g, 'r, 's>( _context: RefContext<'b, 'g, 'r, 's>, diff --git a/src/parser/mod.rs b/src/parser/mod.rs index b3e27101..02dabf6c 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -1,4 +1,5 @@ mod angle_link; +mod babel_call; mod citation; mod citation_reference; mod clock; diff --git a/src/types/lesser_element.rs b/src/types/lesser_element.rs index 8797bbcd..665da39c 100644 --- a/src/types/lesser_element.rs +++ b/src/types/lesser_element.rs @@ -138,7 +138,6 @@ pub struct Keyword<'s> { pub struct BabelCall<'s> { pub source: &'s str, pub name: Option<&'s str>, - pub key: &'s str, pub value: &'s str, } From 68e392811ebd2e538af61939097dfaa785a3b24f Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Thu, 5 Oct 2023 16:32:40 -0400 Subject: [PATCH 2/6] Parse the babel call. --- .../lesser_element/babel_call/empty.org | 3 + .../babel_call/header_arguments.org | 3 + .../babel_call/no_closing_parenthesis.org | 1 + .../lesser_element/babel_call/simple.org | 6 + .../lesser_element/babel_call/spaces.org | 3 + src/compare/diff.rs | 50 ++++++-- src/parser/babel_call.rs | 118 +++++++++++++++++- src/types/lesser_element.rs | 4 + 8 files changed, 176 insertions(+), 12 deletions(-) create mode 100644 org_mode_samples/lesser_element/babel_call/empty.org create mode 100644 org_mode_samples/lesser_element/babel_call/header_arguments.org create mode 100644 org_mode_samples/lesser_element/babel_call/no_closing_parenthesis.org create mode 100644 org_mode_samples/lesser_element/babel_call/spaces.org diff --git a/org_mode_samples/lesser_element/babel_call/empty.org b/org_mode_samples/lesser_element/babel_call/empty.org new file mode 100644 index 00000000..0710532d --- /dev/null +++ b/org_mode_samples/lesser_element/babel_call/empty.org @@ -0,0 +1,3 @@ +#+call: + +#+call: diff --git a/org_mode_samples/lesser_element/babel_call/header_arguments.org b/org_mode_samples/lesser_element/babel_call/header_arguments.org new file mode 100644 index 00000000..5416e05d --- /dev/null +++ b/org_mode_samples/lesser_element/babel_call/header_arguments.org @@ -0,0 +1,3 @@ +#+call: foo[inside](bar="baz")[outside] + +#+call: foo[](bar="baz")[] diff --git a/org_mode_samples/lesser_element/babel_call/no_closing_parenthesis.org b/org_mode_samples/lesser_element/babel_call/no_closing_parenthesis.org new file mode 100644 index 00000000..e9be8254 --- /dev/null +++ b/org_mode_samples/lesser_element/babel_call/no_closing_parenthesis.org @@ -0,0 +1 @@ +#+call: foo(bar="baz" diff --git a/org_mode_samples/lesser_element/babel_call/simple.org b/org_mode_samples/lesser_element/babel_call/simple.org index 281b00cd..bafcb01a 100644 --- a/org_mode_samples/lesser_element/babel_call/simple.org +++ b/org_mode_samples/lesser_element/babel_call/simple.org @@ -1 +1,7 @@ #+call: foo(bar="baz") + +#+call: lorem ipsum + +#+call: dolar cat(dog) + +#+call: (bat) diff --git a/org_mode_samples/lesser_element/babel_call/spaces.org b/org_mode_samples/lesser_element/babel_call/spaces.org new file mode 100644 index 00000000..55f9b850 --- /dev/null +++ b/org_mode_samples/lesser_element/babel_call/spaces.org @@ -0,0 +1,3 @@ +#+call: foo [inside] (bar="baz") [outside] + +#+call: foo (bar="baz") [outside] diff --git a/src/compare/diff.rs b/src/compare/diff.rs index 7f766397..9f9de030 100644 --- a/src/compare/diff.rs +++ b/src/compare/diff.rs @@ -2403,7 +2403,7 @@ fn compare_babel_call<'b, 's>( let mut this_status = DiffStatus::Good; let mut message = None; - // TODO: Compare :call :inside-header :arguments :end-header + // TODO: Compare :inside-header :end-header // TODO: Compare :caption // Compare name @@ -2417,19 +2417,55 @@ fn compare_babel_call<'b, 's>( } // Compare value - let value = unquote( - get_property(emacs, ":value")? - .ok_or("Emacs keywords should have a :value")? - .as_atom()?, - )?; + let value = get_property_quoted_string(emacs, ":value")?.unwrap_or(String::new()); if value != rust.value { this_status = DiffStatus::Bad; message = Some(format!( - "Mismatchs keyword values (emacs != rust) {:?} != {:?}", + "Value mismatch (emacs != rust) {:?} != {:?}", value, rust.value )) } + // Compare call + let call = get_property_quoted_string(emacs, ":call")?; + if call.as_ref().map(String::as_str) != rust.call { + this_status = DiffStatus::Bad; + message = Some(format!( + "Call mismatch (emacs != rust) {:?} != {:?}", + call, rust.call + )) + } + + // Compare arguments + let arguments = get_property_quoted_string(emacs, ":arguments")?; + if arguments.as_ref().map(String::as_str) != rust.arguments { + this_status = DiffStatus::Bad; + message = Some(format!( + "Arguments mismatch (emacs != rust) {:?} != {:?}", + arguments, rust.arguments + )) + } + + // Compare inside header + let inside_header = get_property_quoted_string(emacs, ":inside-header")?; + if inside_header.as_ref().map(String::as_str) != rust.inside_header { + this_status = DiffStatus::Bad; + message = Some(format!( + "Inside header mismatch (emacs != rust) {:?} != {:?}", + inside_header, rust.inside_header + )) + } + + // Compare end header + let end_header = get_property_quoted_string(emacs, ":end-header")?; + if end_header.as_ref().map(String::as_str) != rust.end_header { + this_status = DiffStatus::Bad; + message = Some(format!( + "End header mismatch (emacs != rust) {:?} != {:?}", + end_header, rust.end_header + )) + } + Ok(DiffResult { status: this_status, name: rust.get_elisp_name(), diff --git a/src/parser/babel_call.rs b/src/parser/babel_call.rs index 09613328..79731cf6 100644 --- a/src/parser/babel_call.rs +++ b/src/parser/babel_call.rs @@ -1,10 +1,14 @@ +use nom::branch::alt; use nom::bytes::complete::tag; use nom::bytes::complete::tag_no_case; use nom::character::complete::anychar; +use nom::character::complete::one_of; use nom::character::complete::space0; use nom::combinator::consumed; +use nom::combinator::opt; use nom::combinator::peek; use nom::combinator::recognize; +use nom::combinator::verify; use nom::multi::many0; use nom::multi::many_till; use nom::sequence::tuple; @@ -12,6 +16,7 @@ use nom::InputTake; use super::keyword::affiliated_keyword; use super::util::get_name; +use super::util::start_of_line; use super::OrgSource; use crate::context::RefContext; use crate::error::Res; @@ -26,8 +31,8 @@ pub(crate) fn babel_call<'b, 'g, 'r, 's>( ) -> Res, BabelCall<'s>> { let (input, affiliated_keywords) = many0(affiliated_keyword)(input)?; - let (remaining, (consumed_input, (_, _, parsed_key, _))) = - consumed(tuple((space0, tag("#+"), tag_no_case("call"), tag(":"))))(input)?; + start_of_line(input)?; + let (remaining, _) = tuple((space0, tag("#+"), tag_no_case("call"), tag(":")))(input)?; if let Ok((remaining, (_, line_break))) = tuple((space0, org_line_ending))(remaining) { let source = get_consumed(input, remaining); @@ -37,13 +42,17 @@ pub(crate) fn babel_call<'b, 'g, 'r, 's>( source: Into::<&str>::into(source), name: get_name(&affiliated_keywords), value: Into::<&str>::into(line_break.take(0)), + call: None, + inside_header: None, + arguments: None, + end_header: None, }, )); } let (remaining, _ws) = space0(remaining)?; - let (remaining, parsed_value) = - recognize(many_till(anychar, peek(tuple((space0, org_line_ending)))))(remaining)?; + let (remaining, (value, (call, inside_header, arguments, end_header))) = + consumed(babel_call_value)(remaining)?; let (remaining, _ws) = tuple((space0, org_line_ending))(remaining)?; let source = get_consumed(input, remaining); @@ -53,7 +62,106 @@ pub(crate) fn babel_call<'b, 'g, 'r, 's>( BabelCall { source: Into::<&str>::into(source), name: get_name(&affiliated_keywords), - value: Into::<&str>::into(parsed_value), + value: Into::<&str>::into(value).trim_end(), + call: call.map(Into::<&str>::into), + inside_header: inside_header.map(Into::<&str>::into), + arguments: arguments.map(Into::<&str>::into), + end_header: end_header.map(Into::<&str>::into), }, )) } + +#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +fn babel_call_value<'s>( + input: OrgSource<'s>, +) -> Res< + OrgSource<'s>, + ( + Option>, + Option>, + Option>, + Option>, + ), +> { + let (remaining, call) = opt(babel_call_call)(input)?; + let (remaining, inside_header) = opt(inside_header)(remaining)?; + let (remaining, arguments) = opt(arguments)(remaining)?; + let (remaining, end_header) = opt(end_header)(remaining)?; + Ok(( + remaining, + (call, inside_header, arguments.flatten(), end_header), + )) +} + +#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +fn babel_call_call<'s>(input: OrgSource<'s>) -> Res, OrgSource<'s>> { + verify( + recognize(many_till( + anychar, + alt(( + peek(recognize(one_of("[("))), + recognize(tuple((space0, org_line_ending))), + )), + )), + |s| s.len() > 0, + )(input) +} + +#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +fn inside_header<'s>(input: OrgSource<'s>) -> Res, OrgSource<'s>> { + let (remaining, _) = tag("[")(input)?; + + let contents_start = remaining; + let (remaining, contents) = opt(recognize(many_till( + anychar, + alt(( + peek(recognize(one_of("]"))), + recognize(tuple((space0, org_line_ending))), + )), + )))(remaining)?; + let (remaining, _) = tag("]")(remaining)?; + Ok((remaining, contents.unwrap_or(contents_start.take(0)))) +} + +#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +fn arguments<'s>(input: OrgSource<'s>) -> Res, Option>> { + let (remaining, _) = tag("(")(input)?; + + let (remaining, contents) = opt(verify( + recognize(many_till( + anychar, + alt(( + peek(recognize(one_of(")"))), + recognize(tuple((space0, org_line_ending))), + )), + )), + |s| s.len() > 0, + ))(remaining)?; + let (remaining, _) = tag(")")(remaining)?; + Ok((remaining, contents)) +} + +#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +fn end_header<'s>(input: OrgSource<'s>) -> Res, OrgSource<'s>> { + let (remaining, _) = space0(input)?; + verify( + recognize(many_till(anychar, peek(tuple((space0, org_line_ending))))), + |s| s.len() > 0, + )(remaining) +} + +#[cfg(test)] +mod tests { + use nom::combinator::opt; + + use super::*; + + #[test] + fn simple_call() -> Result<(), Box> { + let input = OrgSource::new("()"); + let (remaining, call) = opt(babel_call_call)(input)?; + assert_eq!(Into::<&str>::into(remaining), "()"); + assert_eq!(call, None); + Ok(()) + } +} diff --git a/src/types/lesser_element.rs b/src/types/lesser_element.rs index 665da39c..ee126d6e 100644 --- a/src/types/lesser_element.rs +++ b/src/types/lesser_element.rs @@ -139,6 +139,10 @@ pub struct BabelCall<'s> { pub source: &'s str, pub name: Option<&'s str>, pub value: &'s str, + pub call: Option<&'s str>, + pub inside_header: Option<&'s str>, + pub arguments: Option<&'s str>, + pub end_header: Option<&'s str>, } #[derive(Debug)] From efac73798f7754a85f00f3d435c06fcae941a877 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Thu, 5 Oct 2023 18:42:20 -0400 Subject: [PATCH 3/6] Add a test showing we need to count brackets. --- .../lesser_element/babel_call/nested_brackets.org | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 org_mode_samples/lesser_element/babel_call/nested_brackets.org diff --git a/org_mode_samples/lesser_element/babel_call/nested_brackets.org b/org_mode_samples/lesser_element/babel_call/nested_brackets.org new file mode 100644 index 00000000..7b94850c --- /dev/null +++ b/org_mode_samples/lesser_element/babel_call/nested_brackets.org @@ -0,0 +1,7 @@ +#+call: foo[inside](bar="baz")[outside] + +#+call: foo[[inside]](bar="baz")[outside] + +#+call: foo[inside]((bar="baz"))[outside] + +#+call: foo[inside](bar="baz")[[outside]] From 885fefd0605b0a02fae25d8e3b25e59ca85ebdbc Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Thu, 5 Oct 2023 19:19:27 -0400 Subject: [PATCH 4/6] Implement generic function for balanced brackets text. --- src/parser/babel_call.rs | 121 ++++++++++++++++++++++++++++++++++----- 1 file changed, 108 insertions(+), 13 deletions(-) diff --git a/src/parser/babel_call.rs b/src/parser/babel_call.rs index 79731cf6..c4bf3120 100644 --- a/src/parser/babel_call.rs +++ b/src/parser/babel_call.rs @@ -15,10 +15,14 @@ use nom::sequence::tuple; use nom::InputTake; use super::keyword::affiliated_keyword; +use super::org_source::BracketDepth; use super::util::get_name; use super::util::start_of_line; use super::OrgSource; +use crate::context::Matcher; use crate::context::RefContext; +use crate::error::CustomError; +use crate::error::MyError; use crate::error::Res; use crate::parser::util::get_consumed; use crate::parser::util::org_line_ending; @@ -125,20 +129,37 @@ fn inside_header<'s>(input: OrgSource<'s>) -> Res, OrgSource<'s>> #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn arguments<'s>(input: OrgSource<'s>) -> Res, Option>> { - let (remaining, _) = tag("(")(input)?; + balanced_bracket( + |i| tag("(")(i), + |i| peek(tag(")"))(i), + |i| recognize(tuple((space0, org_line_ending)))(i), + |i| tag(")")(i), + |s| s.get_parenthesis_depth(), + )(input) - let (remaining, contents) = opt(verify( - recognize(many_till( - anychar, - alt(( - peek(recognize(one_of(")"))), - recognize(tuple((space0, org_line_ending))), - )), - )), - |s| s.len() > 0, - ))(remaining)?; - let (remaining, _) = tag(")")(remaining)?; - Ok((remaining, contents)) + // impl_balanced_bracket( + // input, + // |i| tag("(")(i), + // |i| peek(tag(")"))(i), + // |i| recognize(tuple((space0, org_line_ending)))(i), + // |i| tag(")")(i), + // |s| s.get_parenthesis_depth(), + // ) + + // let (remaining, _) = tag("(")(input)?; + + // let (remaining, contents) = opt(verify( + // recognize(many_till( + // anychar, + // alt(( + // peek(recognize(one_of(")"))), + // recognize(tuple((space0, org_line_ending))), + // )), + // )), + // |s| s.len() > 0, + // ))(remaining)?; + // let (remaining, _) = tag(")")(remaining)?; + // Ok((remaining, contents)) } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] @@ -150,6 +171,80 @@ fn end_header<'s>(input: OrgSource<'s>) -> Res, OrgSource<'s>> { )(remaining) } +fn balanced_bracket< + O: Matcher, + S: Matcher, + F: Matcher, + E: Matcher, + D: for<'ss> Fn(OrgSource<'ss>) -> BracketDepth, +>( + opening_parser: O, + stop_parser: S, + fail_parser: F, + end_parser: E, + depth_function: D, +) -> impl for<'s> Fn(OrgSource<'s>) -> Res, Option>> { + move |input| { + impl_balanced_bracket::<&O, &S, &F, &E, &D>( + input, + &opening_parser, + &stop_parser, + &fail_parser, + &end_parser, + &depth_function, + ) + } +} + +fn impl_balanced_bracket< + 's, + O: Matcher, + S: Matcher, + F: Matcher, + E: Matcher, + D: for<'ss> Fn(OrgSource<'ss>) -> BracketDepth, +>( + input: OrgSource<'s>, + opening_parser: O, + stop_parser: S, + fail_parser: F, + end_parser: E, + depth_function: D, +) -> Res, Option>> { + let (mut remaining, _) = opening_parser(input)?; + let contents_start = remaining; + let original_depth = depth_function(remaining); + + loop { + let bracket_depth = depth_function(remaining); + if bracket_depth == original_depth { + let (remain, stop_result) = opt(&stop_parser)(remaining)?; + remaining = remain; + if stop_result.is_some() { + break; + } + } + + if fail_parser(remaining).is_ok() { + return Err(nom::Err::Error(CustomError::MyError(MyError( + "Fail parser matched.", + )))); + } + + let (remain, _) = anychar(remaining)?; + remaining = remain; + } + let contents_end = remaining; + + let (remaining, _) = end_parser(remaining)?; + let contents = if contents_start != contents_end { + Some(contents_start.get_until(contents_end)) + } else { + None + }; + Ok((remaining, contents)) +} + #[cfg(test)] mod tests { use nom::combinator::opt; From fa9712418641089b2c2ce29781a91015c97ba8e2 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Thu, 5 Oct 2023 19:49:07 -0400 Subject: [PATCH 5/6] Handle nesting of brackets. --- src/parser/babel_call.rs | 43 ++++++++-------------------------------- 1 file changed, 8 insertions(+), 35 deletions(-) diff --git a/src/parser/babel_call.rs b/src/parser/babel_call.rs index c4bf3120..29194223 100644 --- a/src/parser/babel_call.rs +++ b/src/parser/babel_call.rs @@ -113,17 +113,14 @@ fn babel_call_call<'s>(input: OrgSource<'s>) -> Res, OrgSource<'s> #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn inside_header<'s>(input: OrgSource<'s>) -> Res, OrgSource<'s>> { - let (remaining, _) = tag("[")(input)?; - - let contents_start = remaining; - let (remaining, contents) = opt(recognize(many_till( - anychar, - alt(( - peek(recognize(one_of("]"))), - recognize(tuple((space0, org_line_ending))), - )), - )))(remaining)?; - let (remaining, _) = tag("]")(remaining)?; + let (remaining, contents) = balanced_bracket( + |i| tag("[")(i), + |i| peek(tag("]"))(i), + |i| recognize(tuple((space0, org_line_ending)))(i), + |i| tag("]")(i), + |s| s.get_bracket_depth(), + )(input)?; + let (contents_start, _) = tag("[")(input)?; Ok((remaining, contents.unwrap_or(contents_start.take(0)))) } @@ -136,30 +133,6 @@ fn arguments<'s>(input: OrgSource<'s>) -> Res, Option 0, - // ))(remaining)?; - // let (remaining, _) = tag(")")(remaining)?; - // Ok((remaining, contents)) } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] From 823426a4f19672d2b7b9b08d796b77124ad0ac45 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Thu, 5 Oct 2023 20:04:52 -0400 Subject: [PATCH 6/6] Cleanup. --- src/compare/diff.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/compare/diff.rs b/src/compare/diff.rs index 9f9de030..2cf311ef 100644 --- a/src/compare/diff.rs +++ b/src/compare/diff.rs @@ -2403,8 +2403,6 @@ fn compare_babel_call<'b, 's>( let mut this_status = DiffStatus::Good; let mut message = None; - // TODO: Compare :inside-header :end-header - // TODO: Compare :caption // Compare name let name = get_property_quoted_string(emacs, ":name")?;