Add use_brackets.
This commit is contained in:
parent
ef591556fe
commit
7fe7e7a6ea
@ -159,3 +159,24 @@ pub(crate) fn compare_property_list_of_quoted_string<
|
|||||||
}
|
}
|
||||||
Ok(None)
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -7,6 +7,7 @@ use std::collections::HashSet;
|
|||||||
use super::compare_field::compare_identity;
|
use super::compare_field::compare_identity;
|
||||||
use super::compare_field::compare_noop;
|
use super::compare_field::compare_noop;
|
||||||
use super::compare_field::compare_property_always_nil;
|
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_list_of_quoted_string;
|
||||||
use super::compare_field::compare_property_quoted_string;
|
use super::compare_field::compare_property_quoted_string;
|
||||||
use super::compare_field::compare_property_unquoted_atom;
|
use super::compare_field::compare_property_unquoted_atom;
|
||||||
@ -3129,38 +3130,39 @@ fn compare_entity<'b, 's>(
|
|||||||
),
|
),
|
||||||
(
|
(
|
||||||
EmacsField::Required(":latex"),
|
EmacsField::Required(":latex"),
|
||||||
compare_identity,
|
|r| Some(r.latex),
|
||||||
compare_noop
|
compare_property_quoted_string
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
EmacsField::Required(":latex-math-p"),
|
EmacsField::Required(":latex-math-p"),
|
||||||
compare_identity,
|
|r| r.latex_math_mode,
|
||||||
compare_noop
|
compare_property_boolean
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
EmacsField::Required(":html"),
|
EmacsField::Required(":html"),
|
||||||
compare_identity,
|
|r| Some(r.html),
|
||||||
compare_noop
|
compare_property_quoted_string
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
EmacsField::Required(":ascii"),
|
EmacsField::Required(":ascii"),
|
||||||
compare_identity,
|
|r| Some(r.ascii),
|
||||||
compare_noop
|
compare_property_quoted_string
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
|
// latin1... like I give a shit.
|
||||||
EmacsField::Required(":latin1"),
|
EmacsField::Required(":latin1"),
|
||||||
compare_identity,
|
compare_identity,
|
||||||
compare_noop
|
compare_noop
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
EmacsField::Required(":utf-8"),
|
EmacsField::Required(":utf-8"),
|
||||||
compare_identity,
|
|r| Some(r.utf8),
|
||||||
compare_noop
|
compare_property_quoted_string
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
EmacsField::Required(":use-brackets-p"),
|
EmacsField::Required(":use-brackets-p"),
|
||||||
compare_identity,
|
|r| r.use_brackets,
|
||||||
compare_noop
|
compare_property_boolean
|
||||||
)
|
)
|
||||||
)? {
|
)? {
|
||||||
this_status = new_status;
|
this_status = new_status;
|
||||||
|
@ -2,6 +2,7 @@ use nom::branch::alt;
|
|||||||
use nom::bytes::complete::tag;
|
use nom::bytes::complete::tag;
|
||||||
use nom::character::complete::satisfy;
|
use nom::character::complete::satisfy;
|
||||||
use nom::combinator::eof;
|
use nom::combinator::eof;
|
||||||
|
use nom::combinator::map;
|
||||||
use nom::combinator::peek;
|
use nom::combinator::peek;
|
||||||
use nom::combinator::recognize;
|
use nom::combinator::recognize;
|
||||||
use nom::sequence::tuple;
|
use nom::sequence::tuple;
|
||||||
@ -22,7 +23,7 @@ pub(crate) fn entity<'b, 'g, 'r, 's>(
|
|||||||
input: OrgSource<'s>,
|
input: OrgSource<'s>,
|
||||||
) -> Res<OrgSource<'s>, Entity<'s>> {
|
) -> Res<OrgSource<'s>, Entity<'s>> {
|
||||||
let (remaining, _) = tag("\\")(input)?;
|
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) =
|
let (remaining, _trailing_whitespace) =
|
||||||
maybe_consume_object_trailing_whitespace_if_not_exiting(context, remaining)?;
|
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,
|
html: entity_definition.html,
|
||||||
ascii: entity_definition.ascii,
|
ascii: entity_definition.ascii,
|
||||||
utf8: entity_definition.utf8,
|
utf8: entity_definition.utf8,
|
||||||
|
use_brackets,
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
@ -46,15 +48,18 @@ pub(crate) fn entity<'b, 'g, 'r, 's>(
|
|||||||
fn name<'b, 'g, 'r, 's>(
|
fn name<'b, 'g, 'r, 's>(
|
||||||
context: RefContext<'b, 'g, 'r, 's>,
|
context: RefContext<'b, 'g, 'r, 's>,
|
||||||
input: OrgSource<'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 {
|
for entity in context.get_global_settings().entities {
|
||||||
let result = tuple((
|
let result = tuple((
|
||||||
tag::<_, _, CustomError<_>>(entity.name),
|
tag::<_, _, CustomError<_>>(entity.name),
|
||||||
alt((tag("{}"), peek(recognize(entity_end)))),
|
alt((
|
||||||
|
map(tag("{}"), |_| true),
|
||||||
|
map(peek(recognize(entity_end)), |_| false),
|
||||||
|
)),
|
||||||
))(input);
|
))(input);
|
||||||
match result {
|
match result {
|
||||||
Ok((remaining, (ent, _))) => {
|
Ok((remaining, (ent, use_brackets))) => {
|
||||||
return Ok((remaining, (entity, ent)));
|
return Ok((remaining, (entity, ent, use_brackets)));
|
||||||
}
|
}
|
||||||
Err(_) => {}
|
Err(_) => {}
|
||||||
}
|
}
|
||||||
|
@ -174,6 +174,7 @@ pub struct Entity<'s> {
|
|||||||
pub ascii: &'s str,
|
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.
|
// 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 utf8: &'s str,
|
||||||
|
pub use_brackets: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user