Compare commits
5 Commits
ea29ad8667
...
c49556bd5d
Author | SHA1 | Date | |
---|---|---|---|
![]() |
c49556bd5d | ||
![]() |
84ec2f2023 | ||
![]() |
00ed63dcaa | ||
![]() |
8dde8ce4e1 | ||
![]() |
4e551e6d7e |
@ -15,6 +15,8 @@ use super::elisp_fact::ElispFact;
|
|||||||
use super::elisp_fact::GetElispFact;
|
use super::elisp_fact::GetElispFact;
|
||||||
use super::sexp::unquote;
|
use super::sexp::unquote;
|
||||||
use super::sexp::Token;
|
use super::sexp::Token;
|
||||||
|
use super::util::assert_no_children;
|
||||||
|
use super::util::compare_children;
|
||||||
use super::util::compare_standard_properties;
|
use super::util::compare_standard_properties;
|
||||||
use super::util::get_property;
|
use super::util::get_property;
|
||||||
use super::util::get_property_boolean;
|
use super::util::get_property_boolean;
|
||||||
@ -336,7 +338,7 @@ fn artificial_diff_scope<'b, 's>(
|
|||||||
.into())
|
.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compare_ast_node<'b, 's>(
|
pub(crate) fn compare_ast_node<'b, 's>(
|
||||||
source: &'s str,
|
source: &'s str,
|
||||||
emacs: &'b Token<'s>,
|
emacs: &'b Token<'s>,
|
||||||
rust: AstNode<'b, 's>,
|
rust: AstNode<'b, 's>,
|
||||||
@ -2906,6 +2908,15 @@ fn compare_radio_target<'b, 's>(
|
|||||||
let mut child_status = Vec::new();
|
let mut child_status = Vec::new();
|
||||||
let mut message = None;
|
let mut message = None;
|
||||||
|
|
||||||
|
compare_children(
|
||||||
|
source,
|
||||||
|
emacs,
|
||||||
|
&rust.children,
|
||||||
|
&mut child_status,
|
||||||
|
&mut this_status,
|
||||||
|
&mut message,
|
||||||
|
)?;
|
||||||
|
|
||||||
if let Some((new_status, new_message)) = compare_properties!(
|
if let Some((new_status, new_message)) = compare_properties!(
|
||||||
emacs,
|
emacs,
|
||||||
rust,
|
rust,
|
||||||
@ -3185,10 +3196,21 @@ fn compare_latex_fragment<'b, 's>(
|
|||||||
emacs: &'b Token<'s>,
|
emacs: &'b Token<'s>,
|
||||||
rust: &'b LatexFragment<'s>,
|
rust: &'b LatexFragment<'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 message = None;
|
||||||
|
|
||||||
// TODO: Compare :value
|
if let Some((new_status, new_message)) = compare_properties!(
|
||||||
|
emacs,
|
||||||
|
rust,
|
||||||
|
(
|
||||||
|
EmacsField::Required(":value"),
|
||||||
|
|r| Some(r.value),
|
||||||
|
compare_property_quoted_string
|
||||||
|
)
|
||||||
|
)? {
|
||||||
|
this_status = new_status;
|
||||||
|
message = new_message;
|
||||||
|
}
|
||||||
|
|
||||||
Ok(DiffResult {
|
Ok(DiffResult {
|
||||||
status: this_status,
|
status: this_status,
|
||||||
@ -3206,10 +3228,28 @@ fn compare_export_snippet<'b, 's>(
|
|||||||
emacs: &'b Token<'s>,
|
emacs: &'b Token<'s>,
|
||||||
rust: &'b ExportSnippet<'s>,
|
rust: &'b ExportSnippet<'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 message = None;
|
||||||
|
|
||||||
// TODO: Compare :back-end :value
|
assert_no_children(emacs, &mut this_status, &mut message)?;
|
||||||
|
|
||||||
|
if let Some((new_status, new_message)) = compare_properties!(
|
||||||
|
emacs,
|
||||||
|
rust,
|
||||||
|
(
|
||||||
|
EmacsField::Required(":back-end"),
|
||||||
|
|r| Some(r.backend),
|
||||||
|
compare_property_quoted_string
|
||||||
|
),
|
||||||
|
(
|
||||||
|
EmacsField::Required(":value"),
|
||||||
|
|r| r.contents,
|
||||||
|
compare_property_quoted_string
|
||||||
|
)
|
||||||
|
)? {
|
||||||
|
this_status = new_status;
|
||||||
|
message = new_message;
|
||||||
|
}
|
||||||
|
|
||||||
Ok(DiffResult {
|
Ok(DiffResult {
|
||||||
status: this_status,
|
status: this_status,
|
||||||
|
@ -1,8 +1,12 @@
|
|||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
|
use super::diff::DiffEntry;
|
||||||
|
use super::diff::DiffStatus;
|
||||||
use super::elisp_fact::GetElispFact;
|
use super::elisp_fact::GetElispFact;
|
||||||
use super::sexp::Token;
|
use super::sexp::Token;
|
||||||
|
use crate::compare::diff::compare_ast_node;
|
||||||
use crate::compare::sexp::unquote;
|
use crate::compare::sexp::unquote;
|
||||||
|
use crate::types::AstNode;
|
||||||
use crate::types::GetStandardProperties;
|
use crate::types::GetStandardProperties;
|
||||||
use crate::types::StandardProperties;
|
use crate::types::StandardProperties;
|
||||||
|
|
||||||
@ -252,3 +256,47 @@ where
|
|||||||
.map_or(Ok(None), |r| r.map(Some))?;
|
.map_or(Ok(None), |r| r.map(Some))?;
|
||||||
Ok(parsed_number)
|
Ok(parsed_number)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn compare_children<'b, 's, 'x, RC>(
|
||||||
|
source: &'s str,
|
||||||
|
emacs: &'b Token<'s>,
|
||||||
|
rust_children: &'x Vec<RC>,
|
||||||
|
child_status: &mut Vec<DiffEntry<'b, 's>>,
|
||||||
|
this_status: &mut DiffStatus,
|
||||||
|
message: &mut Option<String>,
|
||||||
|
) -> Result<(), Box<dyn std::error::Error>>
|
||||||
|
where
|
||||||
|
AstNode<'b, 's>: From<&'x RC>,
|
||||||
|
{
|
||||||
|
let emacs_children = emacs.as_list()?;
|
||||||
|
let emacs_children_length = emacs_children.len() - 2;
|
||||||
|
if emacs_children_length != rust_children.len() {
|
||||||
|
*this_status = DiffStatus::Bad;
|
||||||
|
*message = Some(format!(
|
||||||
|
"Child length mismatch (emacs != rust) {:?} != {:?}",
|
||||||
|
emacs_children_length,
|
||||||
|
rust_children.len()
|
||||||
|
));
|
||||||
|
}
|
||||||
|
for (emacs_child, rust_child) in emacs_children.iter().skip(2).zip(rust_children.iter()) {
|
||||||
|
child_status.push(compare_ast_node(source, emacs_child, rust_child.into())?);
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn assert_no_children<'b, 's>(
|
||||||
|
emacs: &'b Token<'s>,
|
||||||
|
this_status: &mut DiffStatus,
|
||||||
|
message: &mut Option<String>,
|
||||||
|
) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
let emacs_children_length = emacs.as_list()?.len();
|
||||||
|
// 2, one for the name of the node and one for the properties. Children would come after that.
|
||||||
|
if emacs_children_length != 2 {
|
||||||
|
*this_status = DiffStatus::Bad;
|
||||||
|
*message = Some(format!(
|
||||||
|
"Should have no children but emacs has {:?} children.",
|
||||||
|
emacs_children_length - 2,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
@ -36,6 +36,7 @@ pub(crate) fn latex_fragment<'b, 'g, 'r, 's>(
|
|||||||
parser_with_context!(dollar_char_fragment)(context),
|
parser_with_context!(dollar_char_fragment)(context),
|
||||||
parser_with_context!(bordered_dollar_fragment)(context),
|
parser_with_context!(bordered_dollar_fragment)(context),
|
||||||
))(input)?;
|
))(input)?;
|
||||||
|
let value = get_consumed(input, 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);
|
||||||
@ -43,6 +44,7 @@ pub(crate) fn latex_fragment<'b, 'g, 'r, 's>(
|
|||||||
remaining,
|
remaining,
|
||||||
LatexFragment {
|
LatexFragment {
|
||||||
source: source.into(),
|
source: source.into(),
|
||||||
|
value: value.into(),
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
@ -180,6 +180,7 @@ pub struct Entity<'s> {
|
|||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub struct LatexFragment<'s> {
|
pub struct LatexFragment<'s> {
|
||||||
pub source: &'s str,
|
pub source: &'s str,
|
||||||
|
pub value: &'s str,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user