diff --git a/src/compare/compare_field.rs b/src/compare/compare_field.rs index 8cc4138..e0f4413 100644 --- a/src/compare/compare_field.rs +++ b/src/compare/compare_field.rs @@ -159,3 +159,24 @@ pub(crate) fn compare_property_list_of_quoted_string< } Ok(None) } + +pub(crate) fn compare_property_boolean<'b, 's, 'x, R, RG: Fn(R) -> bool>( + emacs: &'b Token<'s>, + rust_node: R, + emacs_field: &'x str, + rust_value_getter: RG, +) -> 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); + if rust_value != value { + let this_status = DiffStatus::Bad; + let message = Some(format!( + "{} mismatch (emacs != rust) {:?} != {:?}", + emacs_field, value, rust_value + )); + Ok(Some((this_status, message))) + } else { + Ok(None) + } +} diff --git a/src/compare/diff.rs b/src/compare/diff.rs index c7ad99d..92b3383 100644 --- a/src/compare/diff.rs +++ b/src/compare/diff.rs @@ -7,6 +7,7 @@ use std::collections::HashSet; 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_quoted_string; use super::compare_field::compare_property_quoted_string; use super::compare_field::compare_property_unquoted_atom; @@ -3129,38 +3130,39 @@ fn compare_entity<'b, 's>( ), ( EmacsField::Required(":latex"), - compare_identity, - compare_noop + |r| Some(r.latex), + compare_property_quoted_string ), ( EmacsField::Required(":latex-math-p"), - compare_identity, - compare_noop + |r| r.latex_math_mode, + compare_property_boolean ), ( EmacsField::Required(":html"), - compare_identity, - compare_noop + |r| Some(r.html), + compare_property_quoted_string ), ( EmacsField::Required(":ascii"), - compare_identity, - compare_noop + |r| Some(r.ascii), + compare_property_quoted_string ), ( + // latin1... like I give a shit. EmacsField::Required(":latin1"), compare_identity, compare_noop ), ( EmacsField::Required(":utf-8"), - compare_identity, - compare_noop + |r| Some(r.utf8), + compare_property_quoted_string ), ( EmacsField::Required(":use-brackets-p"), - compare_identity, - compare_noop + |r| r.use_brackets, + compare_property_boolean ) )? { this_status = new_status; diff --git a/src/parser/entity.rs b/src/parser/entity.rs index 452b970..8e20f6b 100644 --- a/src/parser/entity.rs +++ b/src/parser/entity.rs @@ -2,6 +2,7 @@ use nom::branch::alt; use nom::bytes::complete::tag; use nom::character::complete::satisfy; use nom::combinator::eof; +use nom::combinator::map; use nom::combinator::peek; use nom::combinator::recognize; use nom::sequence::tuple; @@ -22,7 +23,7 @@ pub(crate) fn entity<'b, 'g, 'r, 's>( input: OrgSource<'s>, ) -> Res, Entity<'s>> { let (remaining, _) = tag("\\")(input)?; - let (remaining, (entity_definition, entity_name)) = name(context, remaining)?; + let (remaining, (entity_definition, entity_name, use_brackets)) = name(context, remaining)?; let (remaining, _trailing_whitespace) = maybe_consume_object_trailing_whitespace_if_not_exiting(context, remaining)?; @@ -38,6 +39,7 @@ pub(crate) fn entity<'b, 'g, 'r, 's>( html: entity_definition.html, ascii: entity_definition.ascii, utf8: entity_definition.utf8, + use_brackets, }, )) } @@ -46,15 +48,18 @@ pub(crate) fn entity<'b, 'g, 'r, 's>( fn name<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, -) -> Res, (&'g EntityDefinition<'s>, OrgSource<'s>)> { +) -> Res, (&'g EntityDefinition<'s>, OrgSource<'s>, bool)> { for entity in context.get_global_settings().entities { let result = tuple(( tag::<_, _, CustomError<_>>(entity.name), - alt((tag("{}"), peek(recognize(entity_end)))), + alt(( + map(tag("{}"), |_| true), + map(peek(recognize(entity_end)), |_| false), + )), ))(input); match result { - Ok((remaining, (ent, _))) => { - return Ok((remaining, (entity, ent))); + Ok((remaining, (ent, use_brackets))) => { + return Ok((remaining, (entity, ent, use_brackets))); } Err(_) => {} } diff --git a/src/types/object.rs b/src/types/object.rs index 1683b77..7854653 100644 --- a/src/types/object.rs +++ b/src/types/object.rs @@ -174,6 +174,7 @@ pub struct Entity<'s> { pub ascii: &'s str, // Skipping latin1 because it is detrimental to the future. If anyone out there is using latin1, take a long look in the mirror and change your ways. pub utf8: &'s str, + pub use_brackets: bool, } #[derive(Debug, PartialEq)]