diff --git a/src/compare/compare_field.rs b/src/compare/compare_field.rs index 05a1fdd..8ee4557 100644 --- a/src/compare/compare_field.rs +++ b/src/compare/compare_field.rs @@ -14,7 +14,6 @@ use crate::types::AstNode; #[derive(Debug)] pub(crate) enum EmacsField<'s> { Required(&'s str), - #[allow(dead_code)] Optional(&'s str), } diff --git a/src/compare/diff.rs b/src/compare/diff.rs index 18d1d67..7eeb4d3 100644 --- a/src/compare/diff.rs +++ b/src/compare/diff.rs @@ -3492,13 +3492,21 @@ fn compare_citation<'b, 's>( compare_property_quoted_string ), ( - EmacsField::Required(":prefix"), - |r| Some(r.prefix.iter()), + EmacsField::Optional(":prefix"), + |r| if r.prefix.is_empty() { + None + } else { + Some(r.prefix.iter()) + }, compare_property_list_of_ast_nodes ), ( - EmacsField::Required(":suffix"), - |r| Some(r.suffix.iter()), + EmacsField::Optional(":suffix"), + |r| if r.suffix.is_empty() { + None + } else { + Some(r.suffix.iter()) + }, compare_property_list_of_ast_nodes ) ) { @@ -3544,13 +3552,21 @@ fn compare_citation_reference<'b, 's>( compare_property_quoted_string ), ( - EmacsField::Required(":prefix"), - |r| Some(r.prefix.iter()), + EmacsField::Optional(":prefix"), + |r| if r.prefix.is_empty() { + None + } else { + Some(r.prefix.iter()) + }, compare_property_list_of_ast_nodes ), ( - EmacsField::Required(":suffix"), - |r| Some(r.suffix.iter()), + EmacsField::Optional(":suffix"), + |r| if r.suffix.is_empty() { + None + } else { + Some(r.suffix.iter()) + }, compare_property_list_of_ast_nodes ) ) { diff --git a/src/parser/citation_reference.rs b/src/parser/citation_reference.rs index bd7cc05..66bdafa 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; @@ -56,18 +57,22 @@ 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)) }