Compare properties of subscript and superscript.
This commit is contained in:
parent
86dd526dde
commit
d1ef83afca
@ -3823,20 +3823,48 @@ fn compare_statistics_cookie<'b, 's>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn compare_subscript<'b, 's>(
|
fn compare_subscript<'b, 's>(
|
||||||
_source: &'s str,
|
source: &'s str,
|
||||||
emacs: &'b Token<'s>,
|
emacs: &'b Token<'s>,
|
||||||
rust: &'b Subscript<'s>,
|
rust: &'b Subscript<'s>,
|
||||||
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
|
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
|
||||||
let this_status = DiffStatus::Good;
|
let mut this_status = DiffStatus::Good;
|
||||||
let message = None;
|
let mut child_status = Vec::new();
|
||||||
|
let mut message = None;
|
||||||
|
|
||||||
// TODO: Compare :use-brackets-p
|
compare_children(
|
||||||
|
source,
|
||||||
|
emacs,
|
||||||
|
&rust.children,
|
||||||
|
&mut child_status,
|
||||||
|
&mut this_status,
|
||||||
|
&mut message,
|
||||||
|
)?;
|
||||||
|
|
||||||
|
for diff in compare_properties!(
|
||||||
|
source,
|
||||||
|
emacs,
|
||||||
|
rust,
|
||||||
|
(
|
||||||
|
EmacsField::Required(":use-brackets-p"),
|
||||||
|
|r| r.use_brackets,
|
||||||
|
compare_property_boolean
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
match diff {
|
||||||
|
ComparePropertiesResult::NoChange => {}
|
||||||
|
ComparePropertiesResult::SelfChange(new_status, new_message) => {
|
||||||
|
this_status = new_status;
|
||||||
|
message = new_message
|
||||||
|
}
|
||||||
|
ComparePropertiesResult::DiffEntry(diff_entry) => child_status.push(diff_entry),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok(DiffResult {
|
Ok(DiffResult {
|
||||||
status: this_status,
|
status: this_status,
|
||||||
name: rust.get_elisp_name(),
|
name: rust.get_elisp_name(),
|
||||||
message,
|
message,
|
||||||
children: Vec::new(),
|
children: child_status,
|
||||||
rust_source: rust.get_source(),
|
rust_source: rust.get_source(),
|
||||||
emacs_token: emacs,
|
emacs_token: emacs,
|
||||||
}
|
}
|
||||||
@ -3844,20 +3872,48 @@ fn compare_subscript<'b, 's>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn compare_superscript<'b, 's>(
|
fn compare_superscript<'b, 's>(
|
||||||
_source: &'s str,
|
source: &'s str,
|
||||||
emacs: &'b Token<'s>,
|
emacs: &'b Token<'s>,
|
||||||
rust: &'b Superscript<'s>,
|
rust: &'b Superscript<'s>,
|
||||||
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
|
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
|
||||||
let this_status = DiffStatus::Good;
|
let mut this_status = DiffStatus::Good;
|
||||||
let message = None;
|
let mut child_status = Vec::new();
|
||||||
|
let mut message = None;
|
||||||
|
|
||||||
// TODO: Compare :use-brackets-p
|
compare_children(
|
||||||
|
source,
|
||||||
|
emacs,
|
||||||
|
&rust.children,
|
||||||
|
&mut child_status,
|
||||||
|
&mut this_status,
|
||||||
|
&mut message,
|
||||||
|
)?;
|
||||||
|
|
||||||
|
for diff in compare_properties!(
|
||||||
|
source,
|
||||||
|
emacs,
|
||||||
|
rust,
|
||||||
|
(
|
||||||
|
EmacsField::Required(":use-brackets-p"),
|
||||||
|
|r| r.use_brackets,
|
||||||
|
compare_property_boolean
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
match diff {
|
||||||
|
ComparePropertiesResult::NoChange => {}
|
||||||
|
ComparePropertiesResult::SelfChange(new_status, new_message) => {
|
||||||
|
this_status = new_status;
|
||||||
|
message = new_message
|
||||||
|
}
|
||||||
|
ComparePropertiesResult::DiffEntry(diff_entry) => child_status.push(diff_entry),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok(DiffResult {
|
Ok(DiffResult {
|
||||||
status: this_status,
|
status: this_status,
|
||||||
name: rust.get_elisp_name(),
|
name: rust.get_elisp_name(),
|
||||||
message,
|
message,
|
||||||
children: Vec::new(),
|
children: child_status,
|
||||||
rust_source: rust.get_source(),
|
rust_source: rust.get_source(),
|
||||||
emacs_token: emacs,
|
emacs_token: emacs,
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,7 @@ use crate::error::MyError;
|
|||||||
use crate::error::Res;
|
use crate::error::Res;
|
||||||
use crate::parser::util::get_consumed;
|
use crate::parser::util::get_consumed;
|
||||||
use crate::types::Object;
|
use crate::types::Object;
|
||||||
|
use crate::types::PlainText;
|
||||||
use crate::types::Subscript;
|
use crate::types::Subscript;
|
||||||
use crate::types::Superscript;
|
use crate::types::Superscript;
|
||||||
|
|
||||||
@ -57,14 +58,22 @@ pub(crate) fn subscript<'b, 'g, 'r, 's>(
|
|||||||
// We check for the underscore first before checking the pre-character as a minor optimization to avoid walking up the context tree to find the document root unnecessarily.
|
// We check for the underscore first before checking the pre-character as a minor optimization to avoid walking up the context tree to find the document root unnecessarily.
|
||||||
let (remaining, _) = tag("_")(input)?;
|
let (remaining, _) = tag("_")(input)?;
|
||||||
pre(input)?;
|
pre(input)?;
|
||||||
let (remaining, _body) = script_body(context, remaining)?;
|
let (remaining, body) = script_body(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)?;
|
||||||
let source = get_consumed(input, remaining);
|
let source = get_consumed(input, remaining);
|
||||||
|
|
||||||
|
let (use_brackets, body) = match body {
|
||||||
|
ScriptBody::Braceless(text) => (false, vec![Object::PlainText(PlainText { source: text })]),
|
||||||
|
ScriptBody::WithBraces(body) => (true, body),
|
||||||
|
};
|
||||||
|
|
||||||
Ok((
|
Ok((
|
||||||
remaining,
|
remaining,
|
||||||
Subscript {
|
Subscript {
|
||||||
source: source.into(),
|
source: source.into(),
|
||||||
|
use_brackets,
|
||||||
|
children: body,
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
@ -80,14 +89,22 @@ pub(crate) fn superscript<'b, 'g, 'r, 's>(
|
|||||||
// We check for the circumflex first before checking the pre-character as a minor optimization to avoid walking up the context tree to find the document root unnecessarily.
|
// We check for the circumflex first before checking the pre-character as a minor optimization to avoid walking up the context tree to find the document root unnecessarily.
|
||||||
let (remaining, _) = tag("^")(input)?;
|
let (remaining, _) = tag("^")(input)?;
|
||||||
pre(input)?;
|
pre(input)?;
|
||||||
let (remaining, _body) = script_body(context, remaining)?;
|
let (remaining, body) = script_body(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)?;
|
||||||
let source = get_consumed(input, remaining);
|
let source = get_consumed(input, remaining);
|
||||||
|
|
||||||
|
let (use_brackets, body) = match body {
|
||||||
|
ScriptBody::Braceless(text) => (false, vec![Object::PlainText(PlainText { source: text })]),
|
||||||
|
ScriptBody::WithBraces(body) => (true, body),
|
||||||
|
};
|
||||||
|
|
||||||
Ok((
|
Ok((
|
||||||
remaining,
|
remaining,
|
||||||
Superscript {
|
Superscript {
|
||||||
source: source.into(),
|
source: source.into(),
|
||||||
|
use_brackets,
|
||||||
|
children: body,
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
@ -252,11 +252,15 @@ pub struct StatisticsCookie<'s> {
|
|||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub struct Subscript<'s> {
|
pub struct Subscript<'s> {
|
||||||
pub source: &'s str,
|
pub source: &'s str,
|
||||||
|
pub use_brackets: bool,
|
||||||
|
pub children: Vec<Object<'s>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub struct Superscript<'s> {
|
pub struct Superscript<'s> {
|
||||||
pub source: &'s str,
|
pub source: &'s str,
|
||||||
|
pub use_brackets: bool,
|
||||||
|
pub children: Vec<Object<'s>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
|
Loading…
Reference in New Issue
Block a user