From 9bdec391f143f1b808092add0a2eba3992bf4f3a Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sun, 8 Oct 2023 16:39:22 -0400 Subject: [PATCH] Do not capture trailing whitespace on the final macro arg. --- src/parser/org_macro.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/parser/org_macro.rs b/src/parser/org_macro.rs index 4cc6e04..dcc1566 100644 --- a/src/parser/org_macro.rs +++ b/src/parser/org_macro.rs @@ -1,11 +1,13 @@ use nom::bytes::complete::tag; use nom::character::complete::anychar; +use nom::character::complete::space0; use nom::combinator::not; use nom::combinator::opt; use nom::combinator::peek; use nom::combinator::verify; use nom::multi::many0; use nom::multi::separated_list0; +use nom::sequence::tuple; use super::org_source::OrgSource; use super::util::maybe_consume_object_trailing_whitespace_if_not_exiting; @@ -67,7 +69,7 @@ fn org_macro_args<'b, 'g, 'r, 's>( let (remaining, _) = tag("(")(input)?; let (remaining, args) = separated_list0(tag(","), parser_with_context!(org_macro_arg)(context))(remaining)?; - let (remaining, _) = tag(")")(remaining)?; + let (remaining, _) = tuple((space0, tag(")")))(remaining)?; Ok((remaining, args)) } @@ -82,6 +84,10 @@ fn org_macro_arg<'b, 'g, 'r, 's>( loop { not(parser_with_context!(exit_matcher_parser)(context))(remaining)?; not(peek(tag("}}}")))(remaining)?; + if peek(tuple((space0::, CustomError<_>>, tag(")"))))(remaining).is_ok() { + break; + } + let (new_remaining, next_char) = anychar(remaining)?; if escaping { remaining = new_remaining;