Fix handling capitalization in macro names.
All checks were successful
rust-build Build rust-build has succeeded
rust-foreign-document-test Build rust-foreign-document-test has succeeded
rust-test Build rust-test has succeeded

This commit is contained in:
Tom Alexander 2023-10-08 16:51:44 -04:00
parent 9bdec391f1
commit f07d041eb9
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
5 changed files with 34 additions and 14 deletions

View File

@ -0,0 +1 @@
{{{Foo(Bar,Baz)}}}

View File

@ -3077,20 +3077,20 @@ fn compare_org_macro<'b, 's>(
rust, rust,
( (
EmacsField::Required(":key"), EmacsField::Required(":key"),
|r| Some(r.macro_name), |r| Some(r.get_key()),
compare_property_quoted_string compare_property_quoted_string
), ),
( (
EmacsField::Required(":value"), EmacsField::Required(":value"),
|r| Some(r.macro_value), |r| Some(r.value),
compare_property_quoted_string compare_property_quoted_string
), ),
( (
EmacsField::Required(":args"), EmacsField::Required(":args"),
|r| if r.macro_args.is_empty() { |r| if r.args.is_empty() {
None None
} else { } else {
Some(r.get_macro_args()) Some(r.get_args())
}, },
compare_property_list_of_quoted_string compare_property_list_of_quoted_string
) )

View File

@ -37,13 +37,13 @@ pub(crate) fn org_macro<'b, 'g, 'r, 's>(
remaining, remaining,
OrgMacro { OrgMacro {
source: source.into(), source: source.into(),
macro_name: macro_name.into(), key: macro_name.into(),
macro_args: macro_args args: macro_args
.unwrap_or_else(|| Vec::with_capacity(0)) .unwrap_or_else(|| Vec::with_capacity(0))
.into_iter() .into_iter()
.map(|arg| arg.into()) .map(|arg| arg.into())
.collect(), .collect(),
macro_value: Into::<&str>::into(macro_value), value: Into::<&str>::into(macro_value),
}, },
)) ))
} }

View File

@ -5,6 +5,7 @@ use super::util::coalesce_whitespace_escaped;
use super::util::coalesce_whitespace_if_line_break; use super::util::coalesce_whitespace_if_line_break;
use super::util::remove_line_break; use super::util::remove_line_break;
use super::util::remove_whitespace_if_line_break; use super::util::remove_whitespace_if_line_break;
use super::util::to_lowercase;
use super::GetStandardProperties; use super::GetStandardProperties;
use super::StandardProperties; use super::StandardProperties;
@ -149,12 +150,18 @@ pub struct AngleLink<'s> {
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
pub struct OrgMacro<'s> { pub struct OrgMacro<'s> {
pub source: &'s str, pub source: &'s str,
pub macro_name: &'s str,
/// The macro args from the source. /// The key from the source.
/// ///
/// This does not take into account the post-processing that you would get from the upstream emacs org-mode AST. Use `get_macro_args` for an equivalent value. /// This does not take into account the post-processing that you would get from the upstream emacs org-mode AST. Use `get_key` for an equivalent value.
pub macro_args: Vec<&'s str>, pub key: &'s str,
pub macro_value: &'s str,
/// The args from the source.
///
/// This does not take into account the post-processing that you would get from the upstream emacs org-mode AST. Use `get_args` for an equivalent value.
pub args: Vec<&'s str>,
pub value: &'s str,
} }
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
@ -739,8 +746,12 @@ impl<'s> AngleLink<'s> {
} }
impl<'s> OrgMacro<'s> { impl<'s> OrgMacro<'s> {
pub fn get_macro_args<'b>(&'b self) -> impl Iterator<Item = Cow<'s, str>> + 'b { pub fn get_key<'b>(&'b self) -> Cow<'s, str> {
self.macro_args to_lowercase(self.key)
}
pub fn get_args<'b>(&'b self) -> impl Iterator<Item = Cow<'s, str>> + 'b {
self.args
.iter() .iter()
.map(|arg| coalesce_whitespace_escaped('\\', |c| ",".contains(c))(*arg)) .map(|arg| coalesce_whitespace_escaped('\\', |c| ",".contains(c))(*arg))
} }

View File

@ -451,6 +451,14 @@ enum CoalesceWhitespaceEscaped {
}, },
} }
pub(crate) fn to_lowercase<'s>(input: &'s str) -> Cow<'s, str> {
if input.chars().any(|c| !c.is_lowercase()) {
Cow::Owned(input.to_lowercase())
} else {
Cow::Borrowed(input)
}
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;