Add use_brackets.

This commit is contained in:
Tom Alexander 2023-10-08 18:14:48 -04:00
parent ef591556fe
commit 7fe7e7a6ea
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
4 changed files with 46 additions and 17 deletions

View File

@ -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<Option<(DiffStatus, Option<String>)>, Box<dyn std::error::Error>> {
// 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)
}
}

View File

@ -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;

View File

@ -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<OrgSource<'s>, 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<OrgSource<'s>, (&'g EntityDefinition<'s>, OrgSource<'s>)> {
) -> Res<OrgSource<'s>, (&'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(_) => {}
}

View File

@ -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)]