organic/src/compare/diff.rs

2294 lines
68 KiB
Rust
Raw Normal View History

use std::borrow::Cow;
// TODO: Add a check for unexpected keys in the properties
2023-09-08 23:05:04 -04:00
use std::collections::BTreeSet;
2023-08-25 06:46:00 -04:00
use std::collections::HashSet;
use super::elisp_fact::ElispFact;
use super::elisp_fact::GetElispFact;
2023-09-11 15:31:48 -04:00
use super::sexp::unquote;
use super::sexp::Token;
use super::util::compare_standard_properties;
2023-08-29 22:07:23 -04:00
use super::util::get_property;
2023-10-02 10:48:34 -04:00
use super::util::get_property_boolean;
2023-09-29 17:28:50 -04:00
use super::util::get_property_quoted_string;
2023-09-29 13:03:01 -04:00
use super::util::get_property_unquoted_atom;
use crate::iter::AstNode;
2023-09-03 12:52:09 -04:00
use crate::types::AngleLink;
use crate::types::BabelCall;
2023-09-03 12:52:09 -04:00
use crate::types::Bold;
2023-09-15 15:30:13 -04:00
use crate::types::CheckboxType;
2023-09-03 12:52:09 -04:00
use crate::types::Citation;
use crate::types::CitationReference;
use crate::types::Clock;
use crate::types::Code;
use crate::types::Comment;
use crate::types::CommentBlock;
use crate::types::DiarySexp;
use crate::types::Document;
use crate::types::DocumentElement;
use crate::types::Drawer;
use crate::types::DynamicBlock;
use crate::types::Element;
use crate::types::Entity;
use crate::types::ExampleBlock;
use crate::types::ExportBlock;
use crate::types::ExportSnippet;
use crate::types::FixedWidthArea;
use crate::types::FootnoteDefinition;
use crate::types::FootnoteReference;
2023-09-23 19:13:01 -04:00
use crate::types::GetStandardProperties;
2023-09-03 12:52:09 -04:00
use crate::types::GreaterBlock;
use crate::types::Heading;
use crate::types::HorizontalRule;
use crate::types::InlineBabelCall;
use crate::types::InlineSourceBlock;
use crate::types::Italic;
use crate::types::Keyword;
use crate::types::LatexEnvironment;
use crate::types::LatexFragment;
use crate::types::LineBreak;
2023-09-06 18:49:59 -04:00
use crate::types::NodeProperty;
2023-09-03 12:52:09 -04:00
use crate::types::Object;
use crate::types::OrgMacro;
use crate::types::Paragraph;
use crate::types::PlainLink;
use crate::types::PlainList;
use crate::types::PlainListItem;
2023-09-29 18:45:38 -04:00
use crate::types::PlainListItemCounter;
2023-09-29 19:30:02 -04:00
use crate::types::PlainListItemPreBlank;
2023-09-29 13:03:01 -04:00
use crate::types::PlainListType;
2023-09-03 12:52:09 -04:00
use crate::types::PlainText;
use crate::types::Planning;
use crate::types::PriorityCookie;
2023-09-03 12:52:09 -04:00
use crate::types::PropertyDrawer;
use crate::types::RadioLink;
use crate::types::RadioTarget;
use crate::types::RegularLink;
use crate::types::Section;
use crate::types::SrcBlock;
2023-09-23 19:13:01 -04:00
use crate::types::StandardProperties;
2023-09-03 12:52:09 -04:00
use crate::types::StatisticsCookie;
use crate::types::StrikeThrough;
use crate::types::Subscript;
use crate::types::Superscript;
use crate::types::Table;
use crate::types::TableCell;
use crate::types::TableRow;
use crate::types::Target;
use crate::types::Timestamp;
2023-09-06 12:39:03 -04:00
use crate::types::TodoKeywordType;
2023-09-03 12:52:09 -04:00
use crate::types::Underline;
use crate::types::Verbatim;
use crate::types::VerseBlock;
#[derive(Debug)]
pub enum DiffEntry<'b, 's> {
DiffResult(DiffResult<'b, 's>),
DiffLayer(DiffLayer<'b, 's>),
}
#[derive(Debug)]
pub struct DiffResult<'b, 's> {
status: DiffStatus,
name: Cow<'s, str>,
message: Option<String>,
children: Vec<DiffEntry<'b, 's>>,
rust_source: &'s str,
#[allow(dead_code)]
emacs_token: &'b Token<'s>,
}
2023-04-11 19:22:42 -04:00
#[derive(Debug, PartialEq)]
2023-09-11 13:13:28 -04:00
enum DiffStatus {
Good,
Bad,
}
#[derive(Debug)]
pub struct DiffLayer<'b, 's> {
name: Cow<'s, str>,
children: Vec<DiffEntry<'b, 's>>,
}
impl<'b, 's> From<DiffResult<'b, 's>> for DiffEntry<'b, 's> {
fn from(value: DiffResult<'b, 's>) -> Self {
DiffEntry::DiffResult(value)
}
}
impl<'b, 's> From<DiffLayer<'b, 's>> for DiffEntry<'b, 's> {
fn from(value: DiffLayer<'b, 's>) -> Self {
DiffEntry::DiffLayer(value)
}
}
impl<'b, 's> DiffEntry<'b, 's> {
fn has_bad_children(&self) -> bool {
match self {
DiffEntry::DiffResult(diff) => &diff.children,
DiffEntry::DiffLayer(diff) => &diff.children,
}
.iter()
.any(|child| child.is_immediately_bad() || child.has_bad_children())
}
fn is_immediately_bad(&self) -> bool {
match self {
DiffEntry::DiffResult(diff) => diff.status == DiffStatus::Bad,
DiffEntry::DiffLayer(_) => false,
}
}
2023-09-11 13:13:28 -04:00
pub fn is_bad(&self) -> bool {
self.is_immediately_bad() || self.has_bad_children()
}
2023-09-11 13:13:28 -04:00
pub fn print(&self, original_document: &str) -> Result<(), Box<dyn std::error::Error>> {
self.print_indented(0, original_document)
}
fn print_indented(
&self,
indentation: usize,
original_document: &str,
) -> Result<(), Box<dyn std::error::Error>> {
match self {
DiffEntry::DiffResult(diff) => diff.print_indented(indentation, original_document),
DiffEntry::DiffLayer(diff) => diff.print_indented(indentation, original_document),
}
}
}
impl<'b, 's> DiffResult<'b, 's> {
fn print_indented(
&self,
indentation: usize,
original_document: &str,
) -> Result<(), Box<dyn std::error::Error>> {
2023-04-11 19:22:42 -04:00
let status_text = {
match self.status {
DiffStatus::Good => {
if self.has_bad_children() {
2023-08-25 04:09:52 -04:00
format!(
"{color}BADCHILD{reset}",
color = DiffResult::foreground_color(255, 255, 0),
reset = DiffResult::reset_color(),
)
2023-04-11 19:22:42 -04:00
} else {
2023-08-25 04:09:52 -04:00
format!(
"{color}GOOD{reset}",
color = DiffResult::foreground_color(0, 255, 0),
reset = DiffResult::reset_color(),
)
2023-04-11 19:22:42 -04:00
}
2023-04-12 11:35:02 -04:00
}
2023-08-25 04:09:52 -04:00
DiffStatus::Bad => format!(
"{color}BAD{reset}",
color = DiffResult::foreground_color(255, 0, 0),
reset = DiffResult::reset_color(),
),
2023-04-11 19:22:42 -04:00
}
};
let rust_offset = self.rust_source.as_ptr() as usize - original_document.as_ptr() as usize;
2023-08-29 21:49:16 -04:00
let preceding_text = &original_document[..rust_offset];
println!(
"{indentation}{status_text} {name} char({char_offset}) {message}",
indentation = " ".repeat(indentation),
status_text = status_text,
name = self.name,
2023-08-29 21:49:16 -04:00
char_offset = preceding_text.chars().count() + 1,
message = self.message.as_ref().map(|m| m.as_str()).unwrap_or("")
);
for child in self.children.iter() {
child.print_indented(indentation + 1, original_document)?;
}
Ok(())
}
2023-04-11 19:22:42 -04:00
fn has_bad_children(&self) -> bool {
2023-04-12 11:35:02 -04:00
self.children
.iter()
.any(|child| child.is_immediately_bad() || child.has_bad_children())
}
2023-08-25 04:09:52 -04:00
fn foreground_color(red: u8, green: u8, blue: u8) -> String {
if DiffResult::should_use_color() {
format!(
"\x1b[38;2;{red};{green};{blue}m",
red = red,
green = green,
blue = blue
)
} else {
String::new()
}
2023-08-25 04:09:52 -04:00
}
#[allow(dead_code)]
fn background_color(red: u8, green: u8, blue: u8) -> String {
if DiffResult::should_use_color() {
format!(
"\x1b[48;2;{red};{green};{blue}m",
red = red,
green = green,
blue = blue
)
} else {
String::new()
}
2023-08-25 04:09:52 -04:00
}
fn reset_color() -> &'static str {
if DiffResult::should_use_color() {
"\x1b[0m"
} else {
""
}
}
fn should_use_color() -> bool {
!std::env::var("NO_COLOR").is_ok_and(|val| !val.is_empty())
2023-08-25 04:09:52 -04:00
}
}
impl<'b, 's> DiffLayer<'b, 's> {
fn has_bad_children(&self) -> bool {
self.children
.iter()
.any(|child| child.is_immediately_bad() || child.has_bad_children())
}
fn print_indented(
&self,
indentation: usize,
original_document: &str,
) -> Result<(), Box<dyn std::error::Error>> {
let status_text = if self.has_bad_children() {
format!(
"{color}BADCHILD{reset}",
color = DiffResult::foreground_color(255, 255, 0),
reset = DiffResult::reset_color(),
)
} else {
format!(
"{color}GOOD{reset}",
color = DiffResult::foreground_color(0, 255, 0),
reset = DiffResult::reset_color(),
)
};
println!(
"{indentation}{status_text} {name}",
indentation = " ".repeat(indentation),
status_text = status_text,
name = self.name,
);
for child in self.children.iter() {
child.print_indented(indentation + 1, original_document)?;
}
Ok(())
}
}
fn artificial_diff_scope<'b, 's>(
name: &'static str,
children: Vec<DiffEntry<'b, 's>>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
Ok(DiffLayer {
name: name.into(),
children,
}
.into())
}
fn compare_ast_node<'b, 's>(
source: &'s str,
emacs: &'b Token<'s>,
rust: AstNode<'b, 's>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
let compare_result: Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> = match rust {
AstNode::Document(_) => todo!(),
AstNode::Heading(_) => todo!(),
AstNode::Section(_) => todo!(),
AstNode::Paragraph(_) => todo!(),
AstNode::PlainList(_) => todo!(),
AstNode::PlainListItem(_) => todo!(),
AstNode::GreaterBlock(_) => todo!(),
AstNode::DynamicBlock(_) => todo!(),
AstNode::FootnoteDefinition(_) => todo!(),
AstNode::Comment(_) => todo!(),
AstNode::Drawer(_) => todo!(),
AstNode::PropertyDrawer(_) => todo!(),
AstNode::NodeProperty(_) => todo!(),
AstNode::Table(_) => todo!(),
AstNode::TableRow(_) => todo!(),
AstNode::VerseBlock(_) => todo!(),
AstNode::CommentBlock(_) => todo!(),
AstNode::ExampleBlock(_) => todo!(),
AstNode::ExportBlock(_) => todo!(),
AstNode::SrcBlock(_) => todo!(),
AstNode::Clock(_) => todo!(),
AstNode::DiarySexp(_) => todo!(),
AstNode::Planning(_) => todo!(),
AstNode::FixedWidthArea(_) => todo!(),
AstNode::HorizontalRule(_) => todo!(),
AstNode::Keyword(_) => todo!(),
AstNode::BabelCall(_) => todo!(),
AstNode::LatexEnvironment(_) => todo!(),
AstNode::Bold(_) => todo!(),
AstNode::Italic(_) => todo!(),
AstNode::Underline(_) => todo!(),
AstNode::StrikeThrough(_) => todo!(),
AstNode::Code(_) => todo!(),
AstNode::Verbatim(_) => todo!(),
AstNode::PlainText(_) => todo!(),
AstNode::RegularLink(_) => todo!(),
AstNode::RadioLink(_) => todo!(),
AstNode::RadioTarget(_) => todo!(),
AstNode::PlainLink(_) => todo!(),
AstNode::AngleLink(_) => todo!(),
AstNode::OrgMacro(_) => todo!(),
AstNode::Entity(_) => todo!(),
AstNode::LatexFragment(_) => todo!(),
AstNode::ExportSnippet(_) => todo!(),
AstNode::FootnoteReference(_) => todo!(),
AstNode::Citation(_) => todo!(),
AstNode::CitationReference(_) => todo!(),
AstNode::InlineBabelCall(_) => todo!(),
AstNode::InlineSourceBlock(_) => todo!(),
AstNode::LineBreak(_) => todo!(),
AstNode::Target(_) => todo!(),
AstNode::StatisticsCookie(_) => todo!(),
AstNode::Subscript(_) => todo!(),
AstNode::Superscript(_) => todo!(),
AstNode::TableCell(_) => todo!(),
AstNode::Timestamp(node) => compare_timestamp(source, emacs, node),
};
let mut compare_result = match compare_result.unwrap_or_else(|e| {
DiffResult {
status: DiffStatus::Bad,
name: "error!".into(),
message: Some(e.to_string()),
children: Vec::new(),
rust_source: rust.get_standard_properties().get_source(),
emacs_token: emacs,
}
.into()
}) {
DiffEntry::DiffResult(inner) => inner,
DiffEntry::DiffLayer(_) => {
unreachable!("Layers are only interior to DiffResults of AST nodes.")
}
};
match compare_standard_properties(source, emacs, &rust) {
Err(err) => {
compare_result.status = DiffStatus::Bad;
compare_result.message = Some(err.to_string())
}
Ok(_) => {}
}
Ok(compare_result.into())
}
fn compare_element<'b, 's>(
source: &'s str,
emacs: &'s Token<'s>,
rust: &'s Element<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
2023-08-29 14:17:47 -04:00
let compare_result = match rust {
Element::Paragraph(obj) => compare_paragraph(source, emacs, obj),
Element::PlainList(obj) => compare_plain_list(source, emacs, obj),
Element::GreaterBlock(obj) => compare_greater_block(source, emacs, obj),
Element::DynamicBlock(obj) => compare_dynamic_block(source, emacs, obj),
Element::FootnoteDefinition(obj) => compare_footnote_definition(source, emacs, obj),
Element::Comment(obj) => compare_comment(source, emacs, obj),
Element::Drawer(obj) => compare_drawer(source, emacs, obj),
Element::PropertyDrawer(obj) => compare_property_drawer(source, emacs, obj),
Element::Table(obj) => compare_table(source, emacs, obj),
Element::VerseBlock(obj) => compare_verse_block(source, emacs, obj),
Element::CommentBlock(obj) => compare_comment_block(source, emacs, obj),
Element::ExampleBlock(obj) => compare_example_block(source, emacs, obj),
Element::ExportBlock(obj) => compare_export_block(source, emacs, obj),
Element::SrcBlock(obj) => compare_src_block(source, emacs, obj),
Element::Clock(obj) => compare_clock(source, emacs, obj),
Element::DiarySexp(obj) => compare_diary_sexp(source, emacs, obj),
Element::Planning(obj) => compare_planning(source, emacs, obj),
Element::FixedWidthArea(obj) => compare_fixed_width_area(source, emacs, obj),
Element::HorizontalRule(obj) => compare_horizontal_rule(source, emacs, obj),
Element::Keyword(obj) => compare_keyword(source, emacs, obj),
2023-09-06 18:04:53 -04:00
Element::BabelCall(obj) => compare_babel_call(source, emacs, obj),
Element::LatexEnvironment(obj) => compare_latex_environment(source, emacs, obj),
2023-08-29 14:17:47 -04:00
};
let mut compare_result = match compare_result.unwrap_or_else(|e| {
DiffResult {
2023-08-29 14:17:47 -04:00
status: DiffStatus::Bad,
name: "error!".into(),
2023-08-29 14:17:47 -04:00
message: Some(e.to_string()),
children: Vec::new(),
2023-09-23 19:13:01 -04:00
rust_source: rust.get_standard_properties().get_source(),
emacs_token: emacs,
}
.into()
}) {
DiffEntry::DiffResult(inner) => inner,
DiffEntry::DiffLayer(_) => {
unreachable!("Layers are only interior to DiffResults of AST nodes.")
}
};
match compare_standard_properties(source, emacs, rust) {
Err(err) => {
compare_result.status = DiffStatus::Bad;
compare_result.message = Some(err.to_string())
}
Ok(_) => {}
}
Ok(compare_result.into())
}
fn compare_object<'b, 's>(
source: &'s str,
emacs: &'s Token<'s>,
rust: &'s Object<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
2023-08-29 14:17:47 -04:00
let compare_result = match rust {
Object::Bold(obj) => compare_bold(source, emacs, obj),
Object::Italic(obj) => compare_italic(source, emacs, obj),
Object::Underline(obj) => compare_underline(source, emacs, obj),
Object::Verbatim(obj) => compare_verbatim(source, emacs, obj),
Object::Code(obj) => compare_code(source, emacs, obj),
Object::StrikeThrough(obj) => compare_strike_through(source, emacs, obj),
Object::PlainText(obj) => compare_plain_text(source, emacs, obj),
Object::RegularLink(obj) => compare_regular_link(source, emacs, obj),
Object::RadioLink(obj) => compare_radio_link(source, emacs, obj),
Object::RadioTarget(obj) => compare_radio_target(source, emacs, obj),
2023-07-13 18:18:07 -04:00
Object::PlainLink(obj) => compare_plain_link(source, emacs, obj),
2023-07-13 22:42:42 -04:00
Object::AngleLink(obj) => compare_angle_link(source, emacs, obj),
2023-07-13 23:26:51 -04:00
Object::OrgMacro(obj) => compare_org_macro(source, emacs, obj),
2023-07-18 20:05:39 -04:00
Object::Entity(obj) => compare_entity(source, emacs, obj),
2023-07-18 20:51:06 -04:00
Object::LatexFragment(obj) => compare_latex_fragment(source, emacs, obj),
2023-07-19 00:09:16 -04:00
Object::ExportSnippet(obj) => compare_export_snippet(source, emacs, obj),
Object::FootnoteReference(obj) => compare_footnote_reference(source, emacs, obj),
2023-07-20 00:38:16 -04:00
Object::Citation(obj) => compare_citation(source, emacs, obj),
Object::CitationReference(obj) => compare_citation_reference(source, emacs, obj),
Object::InlineBabelCall(obj) => compare_inline_babel_call(source, emacs, obj),
Object::InlineSourceBlock(obj) => compare_inline_source_block(source, emacs, obj),
2023-07-21 23:48:37 -04:00
Object::LineBreak(obj) => compare_line_break(source, emacs, obj),
2023-07-22 01:15:04 -04:00
Object::Target(obj) => compare_target(source, emacs, obj),
Object::StatisticsCookie(obj) => compare_statistics_cookie(source, emacs, obj),
Object::Subscript(obj) => compare_subscript(source, emacs, obj),
Object::Superscript(obj) => compare_superscript(source, emacs, obj),
2023-07-24 17:34:07 -04:00
Object::Timestamp(obj) => compare_timestamp(source, emacs, obj),
2023-08-29 14:17:47 -04:00
};
let mut compare_result = match compare_result.unwrap_or_else(|e| {
DiffResult {
2023-08-29 14:17:47 -04:00
status: DiffStatus::Bad,
name: rust.get_elisp_fact().get_elisp_name(),
2023-08-29 14:17:47 -04:00
message: Some(e.to_string()),
children: Vec::new(),
2023-09-23 19:13:01 -04:00
rust_source: rust.get_standard_properties().get_source(),
emacs_token: emacs,
}
.into()
}) {
DiffEntry::DiffResult(inner) => inner,
DiffEntry::DiffLayer(_) => {
unreachable!("Layers are only interior to DiffResults of AST nodes.")
}
};
// PlainText is a special case because upstream Org-Mode uses relative values for the bounds in plaintext rather than absolute so the below checks do not account for that.
if let Object::PlainText(_) = rust {
} else {
match compare_standard_properties(source, emacs, rust) {
Err(err) => {
compare_result.status = DiffStatus::Bad;
compare_result.message = Some(err.to_string())
}
Ok(_) => {}
}
}
Ok(compare_result.into())
}
pub fn compare_document<'b, 's>(
emacs: &'s Token<'s>,
rust: &'s Document<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
let children = emacs.as_list()?;
let mut child_status = Vec::new();
let mut this_status = DiffStatus::Good;
let mut message = None;
match compare_standard_properties(rust.source, emacs, rust) {
Err(err) => {
this_status = DiffStatus::Bad;
message = Some(err.to_string())
}
Ok(_) => {}
}
2023-09-29 21:20:23 -04:00
// Compare :path
// :path is a quoted string to the absolute path of the document.
let document_path = get_property_quoted_string(emacs, ":path")?;
2023-09-29 21:20:23 -04:00
let rust_document_path = rust.path.as_ref().map(|p| p.to_str()).flatten();
match (
document_path.as_ref().map(|s| s.as_str()),
rust_document_path,
) {
(None, None) => {}
(None, Some(_)) | (Some(_), None) => {
this_status = DiffStatus::Bad;
message = Some(format!(
"Path mismatch (emacs != rust) {:?} != {:?}",
document_path, rust_document_path
));
}
(Some(e), Some(r)) if e != r => {
this_status = DiffStatus::Bad;
message = Some(format!(
"Path mismatch (emacs != rust) {:?} != {:?}",
document_path, rust_document_path
));
}
(Some(_), Some(_)) => {}
};
2023-09-29 20:23:02 -04:00
// Compare category
// :CATEGORY is specified either from "#+CATEGORY:" or it is the file name without the ".org" extension.
2023-09-29 20:23:02 -04:00
let category = get_property_quoted_string(emacs, ":CATEGORY")?;
match (category.as_ref(), rust.category.as_ref()) {
2023-09-29 20:23:02 -04:00
(None, None) => {}
(None, Some(_)) | (Some(_), None) => {
this_status = DiffStatus::Bad;
message = Some(format!(
"Category mismatch (emacs != rust) {:?} != {:?}",
category, rust.category
));
}
(Some(e), Some(r)) if e != r => {
this_status = DiffStatus::Bad;
message = Some(format!(
"Category mismatch (emacs != rust) {:?} != {:?}",
category, rust.category
));
}
(Some(_), Some(_)) => {}
};
// Skipping "org-data" and its properties
for (i, token) in children.iter().skip(2).enumerate() {
let section_or_headline = token.as_list()?;
let first_cell = section_or_headline
.first()
.ok_or("Should have at least one child.")?
.as_atom()?;
if first_cell == "section" {
if i != 0 {
return Err("Section cannot be after the first child of document.".into());
}
child_status.push(compare_section(
rust.source,
token,
rust.zeroth_section
.as_ref()
.ok_or("No corresponding zeroth-section")?,
)?);
} else if first_cell == "headline" {
let corresponding_heading = rust
.children
.iter()
.nth(i - rust.zeroth_section.as_ref().map(|_| 1).unwrap_or(0))
.ok_or("Should have a corresponding heading.")?;
child_status.push(compare_heading(rust.source, token, corresponding_heading)?);
} else {
2023-09-29 22:27:31 -04:00
return Err(format!(
"Document should only contain sections and headlines, found: {}",
first_cell
)
.into());
}
}
Ok(DiffResult {
status: this_status,
name: rust.get_elisp_name(),
message,
children: child_status,
rust_source: rust.get_source(),
emacs_token: emacs,
}
.into())
}
fn compare_section<'b, 's>(
source: &'s str,
emacs: &'s Token<'s>,
rust: &'s Section<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
let children = emacs.as_list()?;
let mut this_status = DiffStatus::Good;
let mut child_status = Vec::new();
let mut message = None;
match compare_standard_properties(source, emacs, rust) {
Err(err) => {
this_status = DiffStatus::Bad;
message = Some(err.to_string())
}
Ok(_) => {}
}
2023-04-12 11:46:49 -04:00
for (emacs_child, rust_child) in children.iter().skip(2).zip(rust.children.iter()) {
child_status.push(compare_element(source, emacs_child, rust_child)?);
}
Ok(DiffResult {
status: this_status,
name: rust.get_elisp_name(),
message,
children: child_status,
rust_source: rust.get_source(),
emacs_token: emacs,
}
.into())
}
fn compare_heading<'b, 's>(
source: &'s str,
emacs: &'s Token<'s>,
rust: &'s Heading<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
let children = emacs.as_list()?;
let mut child_status = Vec::new();
let mut this_status = DiffStatus::Good;
2023-08-25 06:46:00 -04:00
let mut message = None;
match compare_standard_properties(source, emacs, rust) {
Err(err) => {
this_status = DiffStatus::Bad;
message = Some(err.to_string())
}
Ok(_) => {}
}
2023-08-29 22:07:23 -04:00
// Compare level
2023-08-29 22:11:56 -04:00
let level = get_property(emacs, ":level")?
.ok_or("Level should not be nil")?
.as_atom()?;
if rust.level.to_string() != level {
2023-08-29 22:11:56 -04:00
this_status = DiffStatus::Bad;
message = Some(format!(
2023-09-08 23:05:04 -04:00
"Headline level do not match (emacs != rust): {} != {}",
level, rust.level
2023-08-29 22:11:56 -04:00
))
}
2023-08-29 22:07:23 -04:00
// Compare tags
let emacs_tags = get_tags_from_heading(emacs)?;
let emacs_tags: HashSet<_> = emacs_tags.iter().map(|val| val.as_str()).collect();
let rust_tags: HashSet<&str> = rust.tags.iter().map(|val| *val).collect();
let difference: Vec<&str> = emacs_tags
.symmetric_difference(&rust_tags)
.map(|val| *val)
.collect();
if !difference.is_empty() {
this_status = DiffStatus::Bad;
message = Some(format!("Mismatched tags: {}", difference.join(", ")));
}
// Compare todo-keyword
let todo_keyword = get_property(emacs, ":todo-keyword")?
.map(Token::as_atom)
.map_or(Ok(None), |r| r.map(Some))?
.unwrap_or("nil");
2023-09-06 12:39:03 -04:00
match (todo_keyword, &rust.todo_keyword, unquote(todo_keyword)) {
("nil", None, _) => {}
2023-09-06 12:39:03 -04:00
(_, Some((_rust_todo_type, rust_todo)), Ok(emacs_todo)) if emacs_todo == *rust_todo => {}
(emacs_todo, rust_todo, _) => {
this_status = DiffStatus::Bad;
message = Some(format!(
"(emacs != rust) {:?} != {:?}",
emacs_todo, rust_todo
));
}
};
2023-09-06 12:39:03 -04:00
// Compare todo-type
let todo_type = get_property(emacs, ":todo-type")?
.map(Token::as_atom)
.map_or(Ok(None), |r| r.map(Some))?
.unwrap_or("nil");
// todo-type is an unquoted string either todo, done, or nil
match (todo_type, &rust.todo_keyword) {
("nil", None) => {}
("todo", Some((TodoKeywordType::Todo, _))) => {}
("done", Some((TodoKeywordType::Done, _))) => {}
(emacs_todo, rust_todo) => {
this_status = DiffStatus::Bad;
message = Some(format!(
"(emacs != rust) {:?} != {:?}",
emacs_todo, rust_todo
));
}
};
// Compare title
let title = get_property(emacs, ":title")?;
match (title, rust.title.len()) {
(None, 0) => {}
(None, _) => {
this_status = DiffStatus::Bad;
message = Some(format!(
"Titles do not match (emacs != rust): {:?} != {:?}",
title, rust.title
))
}
(Some(title), _) => {
let title_status = title
.as_list()?
.iter()
.zip(rust.title.iter())
.map(|(emacs_child, rust_child)| compare_object(source, emacs_child, rust_child))
.collect::<Result<Vec<_>, _>>()?;
child_status.push(artificial_diff_scope("title", title_status)?);
}
};
// Compare priority
let priority = get_property(emacs, ":priority")?;
match (priority, rust.priority_cookie) {
(None, None) => {}
(None, Some(_)) | (Some(_), None) => {
this_status = DiffStatus::Bad;
message = Some(format!(
"Priority cookie mismatch (emacs != rust) {:?} != {:?}",
priority, rust.priority_cookie
));
}
(Some(emacs_priority_cookie), Some(rust_priority_cookie)) => {
let emacs_priority_cookie =
emacs_priority_cookie.as_atom()?.parse::<PriorityCookie>()?;
if emacs_priority_cookie != rust_priority_cookie {
this_status = DiffStatus::Bad;
message = Some(format!(
"Priority cookie mismatch (emacs != rust) {:?} != {:?}",
emacs_priority_cookie, rust_priority_cookie
));
}
}
}
// Compare archived
let archived = get_property(emacs, ":archivedp")?;
match (archived, rust.is_archived) {
(None, true) | (Some(_), false) => {
this_status = DiffStatus::Bad;
message = Some(format!(
"archived mismatch (emacs != rust) {:?} != {:?}",
archived, rust.is_archived
));
}
(None, false) | (Some(_), true) => {}
}
// Compare commented
let commented = get_property(emacs, ":commentedp")?;
match (commented, rust.is_comment) {
(None, true) | (Some(_), false) => {
this_status = DiffStatus::Bad;
message = Some(format!(
"commented mismatch (emacs != rust) {:?} != {:?}",
commented, rust.is_comment
));
}
(None, false) | (Some(_), true) => {}
}
2023-09-30 19:21:24 -04:00
// Compare raw-value
let raw_value = get_property_quoted_string(emacs, ":raw-value")?
.ok_or("Headlines should have :raw-value.")?;
let rust_raw_value = rust.get_raw_value();
if raw_value != rust_raw_value {
this_status = DiffStatus::Bad;
message = Some(format!(
"raw-value mismatch (emacs != rust) {:?} != {:?}",
raw_value, rust_raw_value
));
}
2023-10-02 10:48:34 -04:00
// Compare footnote-section-p
let footnote_section = get_property_boolean(emacs, ":footnote-section-p")?;
if footnote_section != rust.is_footnote_section {
this_status = DiffStatus::Bad;
message = Some(format!(
"footnote section mismatch (emacs != rust) {:?} != {:?}",
footnote_section, rust.is_footnote_section
));
}
// TODO: Compare :pre-blank :scheduled :closed
//
// :scheduled and :closed seem to only appear when the headline has a planning
// Compare section
let section_status = children
.iter()
.skip(2)
.zip(rust.children.iter())
.map(|(emacs_child, rust_child)| match rust_child {
2023-04-12 11:35:02 -04:00
DocumentElement::Heading(rust_heading) => {
compare_heading(source, emacs_child, rust_heading)
2023-04-12 13:16:25 -04:00
}
2023-04-12 11:35:02 -04:00
DocumentElement::Section(rust_section) => {
compare_section(source, emacs_child, rust_section)
2023-04-12 13:16:25 -04:00
}
})
.collect::<Result<Vec<_>, _>>()?;
child_status.push(artificial_diff_scope("section", section_status)?);
2023-04-12 11:35:02 -04:00
Ok(DiffResult {
status: this_status,
name: rust.get_elisp_name(),
2023-08-25 06:46:00 -04:00
message,
children: child_status,
rust_source: rust.get_source(),
emacs_token: emacs,
}
.into())
}
2023-04-12 11:46:49 -04:00
2023-08-25 06:46:00 -04:00
fn get_tags_from_heading<'s>(
emacs: &'s Token<'s>,
) -> Result<HashSet<String>, Box<dyn std::error::Error>> {
let tags = match get_property(emacs, ":tags")? {
Some(prop) => prop,
None => return Ok(HashSet::new()),
};
2023-08-25 06:46:00 -04:00
match tags.as_atom() {
Ok(val) => panic!("Unexpected value for tags: {:?}", val),
Err(_) => {}
};
let tags = {
let tags = tags.as_list()?;
let strings = tags
.iter()
.map(Token::as_atom)
.collect::<Result<Vec<&str>, _>>()?;
strings
.into_iter()
.map(unquote)
.collect::<Result<HashSet<String>, _>>()?
2023-08-25 06:46:00 -04:00
};
Ok(tags)
}
fn compare_paragraph<'b, 's>(
2023-04-12 11:46:49 -04:00
source: &'s str,
emacs: &'s Token<'s>,
rust: &'s Paragraph<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
2023-04-12 11:46:49 -04:00
let children = emacs.as_list()?;
let mut child_status = Vec::new();
let this_status = DiffStatus::Good;
let message = None;
2023-04-12 11:46:49 -04:00
for (emacs_child, rust_child) in children.iter().skip(2).zip(rust.children.iter()) {
child_status.push(compare_object(source, emacs_child, rust_child)?);
}
2023-04-12 11:46:49 -04:00
Ok(DiffResult {
status: this_status,
name: rust.get_elisp_name(),
message,
2023-04-12 11:46:49 -04:00
children: child_status,
rust_source: rust.get_source(),
emacs_token: emacs,
}
.into())
2023-04-12 11:46:49 -04:00
}
2023-04-12 13:16:25 -04:00
fn compare_plain_list<'b, 's>(
2023-04-12 13:16:25 -04:00
source: &'s str,
emacs: &'s Token<'s>,
rust: &'s PlainList<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
2023-04-12 13:16:25 -04:00
let children = emacs.as_list()?;
let mut child_status = Vec::new();
2023-09-29 13:03:01 -04:00
let mut this_status = DiffStatus::Good;
let mut message = None;
2023-09-29 18:45:38 -04:00
// Compare type
// :type is an unquoted atom of either descriptive, ordered, or unordered
2023-09-29 13:03:01 -04:00
let list_type = get_property_unquoted_atom(emacs, ":type")?;
match (list_type, &rust.list_type) {
(None, _) => panic!("Emacs returned a list with no type."),
(Some("unordered"), PlainListType::Unordered) => {}
(Some("ordered"), PlainListType::Ordered) => {}
(Some("descriptive"), PlainListType::Descriptive) => {}
_ => {
this_status = DiffStatus::Bad;
message = Some(format!(
"List type mismatch (emacs != rust) {:?} != {:?}",
list_type, rust.list_type
));
}
}
for (emacs_child, rust_child) in children.iter().skip(2).zip(rust.children.iter()) {
child_status.push(compare_plain_list_item(source, emacs_child, rust_child)?);
}
2023-04-12 13:16:25 -04:00
Ok(DiffResult {
status: this_status,
name: rust.get_elisp_name(),
message,
2023-04-12 13:16:25 -04:00
children: child_status,
rust_source: rust.get_source(),
emacs_token: emacs,
}
.into())
2023-04-12 13:16:25 -04:00
}
fn compare_plain_list_item<'b, 's>(
source: &'s str,
emacs: &'s Token<'s>,
rust: &'s PlainListItem<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
let children = emacs.as_list()?;
let mut child_status = Vec::new();
let mut this_status = DiffStatus::Good;
let mut message = None;
// This is not called from compare_element so we have to duplicate all the common checks here.
match compare_standard_properties(source, emacs, rust) {
Err(err) => {
this_status = DiffStatus::Bad;
message = Some(err.to_string())
}
Ok(_) => {}
}
// Compare tag
let tag = get_property(emacs, ":tag")?;
match (tag, rust.tag.is_empty()) {
(None, true) => {}
(None, false) | (Some(_), true) => {
this_status = DiffStatus::Bad;
message = Some("Mismatched tags".to_owned());
}
(Some(tag), false) => {
let tag_status = tag
.as_list()?
.iter()
.zip(rust.tag.iter())
.map(|(emacs_child, rust_child)| compare_object(source, emacs_child, rust_child))
.collect::<Result<Vec<_>, _>>()?;
child_status.push(artificial_diff_scope("tag", tag_status)?);
}
};
// Compare contents
let contents_status = children
.iter()
.skip(2)
.zip(rust.children.iter())
.map(|(emacs_child, rust_child)| compare_element(source, emacs_child, rust_child))
.collect::<Result<Vec<_>, _>>()?;
child_status.push(artificial_diff_scope("contents", contents_status)?);
2023-09-29 18:45:38 -04:00
// Compare bullet
2023-09-29 17:28:50 -04:00
let bullet = get_property_quoted_string(emacs, ":bullet")?
.ok_or("Plain list items must have a :bullet.")?;
if bullet != rust.bullet {
this_status = DiffStatus::Bad;
message = Some(format!(
2023-09-29 18:45:38 -04:00
"Bullet mismatch (emacs != rust) {:?} != {:?}",
2023-09-29 17:28:50 -04:00
bullet, rust.bullet
));
}
2023-09-15 15:30:13 -04:00
2023-09-29 18:45:38 -04:00
// Compare counter
let counter = get_property_unquoted_atom(emacs, ":counter")?;
let counter: Option<PlainListItemCounter> = counter
.map(|val| val.parse())
.map_or(Ok(None), |r| r.map(Some))?;
match (counter, rust.counter) {
(None, None) => {}
(None, Some(_)) | (Some(_), None) => {
this_status = DiffStatus::Bad;
message = Some(format!(
"Counter mismatch (emacs != rust) {:?} != {:?}",
counter, rust.counter
));
}
(Some(e), Some(r)) if e != r => {
this_status = DiffStatus::Bad;
message = Some(format!(
"Counter mismatch (emacs != rust) {:?} != {:?}",
counter, rust.counter
));
}
(Some(_), Some(_)) => {}
};
2023-09-15 15:30:13 -04:00
// Compare checkbox
let checkbox = get_property(emacs, ":checkbox")?
.map(Token::as_atom)
.map_or(Ok(None), |r| r.map(Some))?
.unwrap_or("nil");
match (checkbox, &rust.checkbox) {
("nil", None) => {}
("off", Some((CheckboxType::Off, _))) => {}
("trans", Some((CheckboxType::Trans, _))) => {}
("on", Some((CheckboxType::On, _))) => {}
_ => {
this_status = DiffStatus::Bad;
message = Some(format!(
"Checkbox mismatch (emacs != rust) {:?} != {:?}",
checkbox, rust.checkbox
));
}
};
2023-09-29 19:30:02 -04:00
// Compare pre-blank
// :pre-blank appears to count the line breaks between "::" and the contents in a descriptive list. Oddly enough it does not count the spaces so I'm not quite sure what the value is.
let pre_blank = get_property_unquoted_atom(emacs, ":pre-blank")?;
let pre_blank: Option<PlainListItemPreBlank> = pre_blank
.map(|val| val.parse())
.map_or(Ok(None), |r| r.map(Some))?;
if pre_blank.unwrap_or(0) != rust.pre_blank {
this_status = DiffStatus::Bad;
message = Some(format!(
"Pre-blank mismatch (emacs != rust) {:?} != {:?}",
pre_blank, rust.pre_blank
));
}
2023-09-29 18:45:38 -04:00
Ok(DiffResult {
status: this_status,
name: rust.get_elisp_name(),
message,
children: child_status,
rust_source: rust.get_source(),
emacs_token: emacs,
}
.into())
}
fn compare_greater_block<'b, 's>(
source: &'s str,
emacs: &'s Token<'s>,
rust: &'s GreaterBlock<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
let children = emacs.as_list()?;
let mut child_status = Vec::new();
let this_status = DiffStatus::Good;
let message = None;
// TODO: Special block compare :type :parameters
// Center and quote block has no additional properties
for (emacs_child, rust_child) in children.iter().skip(2).zip(rust.children.iter()) {
child_status.push(compare_element(source, emacs_child, rust_child)?);
}
Ok(DiffResult {
status: this_status,
name: rust.get_elisp_name(),
message,
children: child_status,
rust_source: rust.get_source(),
emacs_token: emacs,
}
.into())
2023-04-19 13:59:17 -04:00
}
fn compare_dynamic_block<'b, 's>(
2023-04-19 13:59:17 -04:00
source: &'s str,
emacs: &'s Token<'s>,
rust: &'s DynamicBlock<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
2023-04-19 13:59:17 -04:00
let children = emacs.as_list()?;
let mut child_status = Vec::new();
let this_status = DiffStatus::Good;
let message = None;
// TODO: Compare :block-name :arguments
2023-04-19 13:59:17 -04:00
for (emacs_child, rust_child) in children.iter().skip(2).zip(rust.children.iter()) {
child_status.push(compare_element(source, emacs_child, rust_child)?);
}
Ok(DiffResult {
status: this_status,
name: rust.get_elisp_name(),
message,
2023-04-19 13:59:17 -04:00
children: child_status,
rust_source: rust.get_source(),
emacs_token: emacs,
}
.into())
}
fn compare_footnote_definition<'b, 's>(
source: &'s str,
emacs: &'s Token<'s>,
rust: &'s FootnoteDefinition<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
let children = emacs.as_list()?;
let mut child_status = Vec::new();
let this_status = DiffStatus::Good;
let message = None;
// TODO: Compare :label :pre-blank
for (emacs_child, rust_child) in children.iter().skip(2).zip(rust.children.iter()) {
child_status.push(compare_element(source, emacs_child, rust_child)?);
}
Ok(DiffResult {
status: this_status,
name: rust.get_elisp_name(),
message,
children: child_status,
rust_source: rust.get_source(),
emacs_token: emacs,
}
.into())
}
2023-04-15 16:53:58 -04:00
fn compare_comment<'b, 's>(
_source: &'s str,
2023-04-15 16:53:58 -04:00
emacs: &'s Token<'s>,
rust: &'s Comment<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
let child_status = Vec::new();
let this_status = DiffStatus::Good;
let message = None;
// TODO: Compare :value
2023-04-15 16:53:58 -04:00
Ok(DiffResult {
status: this_status,
name: rust.get_elisp_name(),
message,
2023-04-15 16:53:58 -04:00
children: child_status,
rust_source: rust.get_source(),
emacs_token: emacs,
}
.into())
2023-04-15 16:53:58 -04:00
}
2023-04-15 18:00:34 -04:00
fn compare_drawer<'b, 's>(
2023-04-15 18:00:34 -04:00
source: &'s str,
emacs: &'s Token<'s>,
rust: &'s Drawer<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
2023-04-15 18:00:34 -04:00
let children = emacs.as_list()?;
let mut child_status = Vec::new();
let this_status = DiffStatus::Good;
let message = None;
// TODO: Compare :drawer-name
2023-04-15 18:00:34 -04:00
for (emacs_child, rust_child) in children.iter().skip(2).zip(rust.children.iter()) {
child_status.push(compare_element(source, emacs_child, rust_child)?);
}
Ok(DiffResult {
status: this_status,
name: rust.get_elisp_name(),
message,
2023-04-15 18:00:34 -04:00
children: child_status,
rust_source: rust.get_source(),
emacs_token: emacs,
}
.into())
2023-04-15 18:00:34 -04:00
}
fn compare_property_drawer<'b, 's>(
source: &'s str,
emacs: &'s Token<'s>,
rust: &'s PropertyDrawer<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
let children = emacs.as_list()?;
2023-09-06 18:49:59 -04:00
let mut child_status = Vec::new();
let this_status = DiffStatus::Good;
let message = None;
2023-09-06 18:49:59 -04:00
for (emacs_child, rust_child) in children.iter().skip(2).zip(rust.children.iter()) {
child_status.push(compare_node_property(source, emacs_child, rust_child)?);
}
Ok(DiffResult {
status: this_status,
name: rust.get_elisp_name(),
message,
children: child_status,
rust_source: rust.get_source(),
emacs_token: emacs,
}
.into())
}
2023-04-19 20:59:58 -04:00
fn compare_node_property<'b, 's>(
2023-09-06 18:49:59 -04:00
source: &'s str,
emacs: &'s Token<'s>,
rust: &'s NodeProperty<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
2023-09-06 18:49:59 -04:00
let child_status = Vec::new();
let mut this_status = DiffStatus::Good;
let mut message = None;
// This is not called from compare_element so we must duplicate all the tests here.
match compare_standard_properties(source, emacs, rust) {
2023-09-06 18:49:59 -04:00
Err(err) => {
this_status = DiffStatus::Bad;
message = Some(err.to_string())
}
Ok(_) => {}
}
2023-09-06 18:49:59 -04:00
// TODO: Compare :key :value
Ok(DiffResult {
status: this_status,
name: rust.get_elisp_name(),
2023-09-06 18:49:59 -04:00
message,
children: child_status,
rust_source: rust.get_source(),
emacs_token: emacs,
}
.into())
}
fn compare_table<'b, 's>(
2023-04-19 20:59:58 -04:00
source: &'s str,
emacs: &'s Token<'s>,
rust: &'s Table<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
2023-04-19 20:59:58 -04:00
let children = emacs.as_list()?;
let mut child_status = Vec::new();
let mut this_status = DiffStatus::Good;
let mut message = None;
2023-04-19 20:59:58 -04:00
2023-09-08 23:05:04 -04:00
// Compare formulas
//
2023-09-08 23:05:04 -04:00
// :tblfm is either nil or a list () filled with quoted strings containing the value for any tblfm keywords at the end of the table.
let emacs_formulas = get_property(emacs, ":tblfm")?;
if let Some(emacs_formulas) = emacs_formulas {
let emacs_formulas = emacs_formulas.as_list()?;
if emacs_formulas.len() != rust.formulas.len() {
this_status = DiffStatus::Bad;
message = Some(format!(
"Formulas do not match (emacs != rust): {:?} != {:?}",
emacs_formulas, rust.formulas
))
} else {
let atoms = emacs_formulas
.into_iter()
.map(Token::as_atom)
.collect::<Result<Vec<_>, _>>()?;
let unquoted = atoms
.into_iter()
.map(unquote)
.collect::<Result<BTreeSet<_>, _>>()?;
for kw in &rust.formulas {
if !unquoted.contains(kw.value) {
this_status = DiffStatus::Bad;
message = Some(format!("Could not find formula in emacs: {}", kw.value))
}
}
}
} else {
if !rust.formulas.is_empty() {
this_status = DiffStatus::Bad;
message = Some(format!(
"Formulas do not match (emacs != rust): {:?} != {:?}",
emacs_formulas, rust.formulas
))
}
}
// TODO: Compare :type :value
for (emacs_child, rust_child) in children.iter().skip(2).zip(rust.children.iter()) {
child_status.push(compare_table_row(source, emacs_child, rust_child)?);
}
Ok(DiffResult {
status: this_status,
name: rust.get_elisp_name(),
message,
children: child_status,
rust_source: rust.get_source(),
emacs_token: emacs,
}
.into())
}
fn compare_table_row<'b, 's>(
source: &'s str,
emacs: &'s Token<'s>,
rust: &'s TableRow<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
let children = emacs.as_list()?;
let mut child_status = Vec::new();
let mut this_status = DiffStatus::Good;
let mut message = None;
// This is not called from compare_element so we must duplicate all the tests here.
match compare_standard_properties(source, emacs, rust) {
Err(err) => {
this_status = DiffStatus::Bad;
message = Some(err.to_string())
}
Ok(_) => {}
}
// TODO: Compare :type
//
// :type is an unquoted atom of either standard or rule
for (emacs_child, rust_child) in children.iter().skip(2).zip(rust.children.iter()) {
child_status.push(compare_table_cell(source, emacs_child, rust_child)?);
}
Ok(DiffResult {
status: this_status,
name: rust.get_elisp_name(),
message,
children: child_status,
rust_source: rust.get_source(),
emacs_token: emacs,
}
.into())
}
fn compare_table_cell<'b, 's>(
source: &'s str,
emacs: &'s Token<'s>,
rust: &'s TableCell<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
let children = emacs.as_list()?;
let child_status = Vec::new();
let mut this_status = DiffStatus::Good;
let mut message = None;
// This is not called from compare_object so we must duplicate all the tests here.
match compare_standard_properties(source, emacs, rust) {
Err(err) => {
this_status = DiffStatus::Bad;
message = Some(err.to_string())
}
Ok(_) => {}
}
for (_emacs_child, _rust_child) in children.iter().skip(2).zip(rust.children.iter()) {}
2023-04-19 20:59:58 -04:00
Ok(DiffResult {
status: this_status,
name: rust.get_elisp_name(),
message,
2023-04-19 20:59:58 -04:00
children: child_status,
rust_source: rust.get_source(),
emacs_token: emacs,
}
.into())
2023-04-19 20:59:58 -04:00
}
fn compare_verse_block<'b, 's>(
_source: &'s str,
emacs: &'s Token<'s>,
rust: &'s VerseBlock<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
2023-04-21 18:05:40 -04:00
let children = emacs.as_list()?;
let child_status = Vec::new();
let this_status = DiffStatus::Good;
let message = None;
2023-04-21 18:05:40 -04:00
for (_emacs_child, _rust_child) in children.iter().skip(2).zip(rust.children.iter()) {}
2023-04-21 18:05:40 -04:00
Ok(DiffResult {
status: this_status,
name: rust.get_elisp_name(),
message,
2023-04-21 18:05:40 -04:00
children: child_status,
rust_source: rust.get_source(),
emacs_token: emacs,
}
.into())
}
fn compare_comment_block<'b, 's>(
_source: &'s str,
emacs: &'s Token<'s>,
rust: &'s CommentBlock<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
let this_status = DiffStatus::Good;
let message = None;
2023-04-21 18:05:40 -04:00
// TODO: Compare :value
2023-04-21 18:05:40 -04:00
Ok(DiffResult {
status: this_status,
name: rust.get_elisp_name(),
message,
2023-04-21 18:05:40 -04:00
children: Vec::new(),
rust_source: rust.get_source(),
emacs_token: emacs,
}
.into())
}
fn compare_example_block<'b, 's>(
_source: &'s str,
emacs: &'s Token<'s>,
rust: &'s ExampleBlock<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
let this_status = DiffStatus::Good;
let message = None;
2023-04-21 18:05:40 -04:00
// TODO: Compare :value :switches :number-lines :preserve-indent :retain-labels :use-labels :label-fmt
2023-04-21 18:05:40 -04:00
Ok(DiffResult {
status: this_status,
name: rust.get_elisp_name(),
message,
2023-04-21 18:05:40 -04:00
children: Vec::new(),
rust_source: rust.get_source(),
emacs_token: emacs,
}
.into())
}
fn compare_export_block<'b, 's>(
_source: &'s str,
emacs: &'s Token<'s>,
rust: &'s ExportBlock<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
let this_status = DiffStatus::Good;
let message = None;
2023-04-21 18:05:40 -04:00
// TODO: Compare :type :value
2023-04-21 18:05:40 -04:00
Ok(DiffResult {
status: this_status,
name: rust.get_elisp_name(),
message,
2023-04-21 18:05:40 -04:00
children: Vec::new(),
rust_source: rust.get_source(),
emacs_token: emacs,
}
.into())
}
fn compare_src_block<'b, 's>(
_source: &'s str,
emacs: &'s Token<'s>,
rust: &'s SrcBlock<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
let this_status = DiffStatus::Good;
let message = None;
2023-04-21 18:05:40 -04:00
2023-09-06 18:11:57 -04:00
// TODO: Compare :language :switches :parameters :number-lines :preserve-indent :retain-labels :use-labels :label-fmt :value
2023-04-21 18:05:40 -04:00
Ok(DiffResult {
status: this_status,
name: rust.get_elisp_name(),
message,
2023-04-21 18:05:40 -04:00
children: Vec::new(),
rust_source: rust.get_source(),
emacs_token: emacs,
}
.into())
}
fn compare_clock<'b, 's>(
_source: &'s str,
emacs: &'s Token<'s>,
rust: &'s Clock<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
let this_status = DiffStatus::Good;
let message = None;
// TODO: Compare :status :value :duration
Ok(DiffResult {
status: this_status,
name: rust.get_elisp_name(),
message,
children: Vec::new(),
rust_source: rust.get_source(),
emacs_token: emacs,
}
.into())
}
2023-04-21 20:22:31 -04:00
fn compare_diary_sexp<'b, 's>(
_source: &'s str,
2023-04-21 20:22:31 -04:00
emacs: &'s Token<'s>,
rust: &'s DiarySexp<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
let this_status = DiffStatus::Good;
let message = None;
2023-04-21 20:22:31 -04:00
// TODO: Compare :value
2023-04-21 20:22:31 -04:00
Ok(DiffResult {
status: this_status,
name: rust.get_elisp_name(),
message,
2023-04-21 20:22:31 -04:00
children: Vec::new(),
rust_source: rust.get_source(),
emacs_token: emacs,
}
.into())
2023-04-21 20:22:31 -04:00
}
2023-04-21 21:33:23 -04:00
fn compare_planning<'b, 's>(
_source: &'s str,
2023-04-21 21:33:23 -04:00
emacs: &'s Token<'s>,
rust: &'s Planning<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
let this_status = DiffStatus::Good;
let message = None;
2023-04-21 21:33:23 -04:00
// TODO: Compare :closed :deadline :scheduled
2023-04-21 21:33:23 -04:00
Ok(DiffResult {
status: this_status,
name: rust.get_elisp_name(),
message,
2023-04-21 21:33:23 -04:00
children: Vec::new(),
rust_source: rust.get_source(),
emacs_token: emacs,
}
.into())
2023-04-21 21:33:23 -04:00
}
2023-04-21 22:04:22 -04:00
fn compare_fixed_width_area<'b, 's>(
_source: &'s str,
2023-04-21 22:04:22 -04:00
emacs: &'s Token<'s>,
rust: &'s FixedWidthArea<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
2023-04-21 22:04:22 -04:00
let child_status = Vec::new();
let this_status = DiffStatus::Good;
let message = None;
2023-04-21 22:04:22 -04:00
// TODO: Compare :value
2023-04-21 22:04:22 -04:00
Ok(DiffResult {
status: this_status,
name: rust.get_elisp_name(),
message,
2023-04-21 22:04:22 -04:00
children: child_status,
rust_source: rust.get_source(),
emacs_token: emacs,
}
.into())
2023-04-21 22:04:22 -04:00
}
2023-04-21 22:23:59 -04:00
fn compare_horizontal_rule<'b, 's>(
_source: &'s str,
2023-04-21 22:23:59 -04:00
emacs: &'s Token<'s>,
rust: &'s HorizontalRule<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
2023-04-21 22:23:59 -04:00
let child_status = Vec::new();
let this_status = DiffStatus::Good;
let message = None;
2023-04-21 22:23:59 -04:00
Ok(DiffResult {
status: this_status,
name: rust.get_elisp_name(),
message,
2023-04-21 22:23:59 -04:00
children: child_status,
rust_source: rust.get_source(),
emacs_token: emacs,
}
.into())
2023-04-21 22:23:59 -04:00
}
2023-04-21 22:33:10 -04:00
fn compare_keyword<'b, 's>(
_source: &'s str,
2023-04-21 22:33:10 -04:00
emacs: &'s Token<'s>,
rust: &'s Keyword<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
2023-04-21 22:33:10 -04:00
let child_status = Vec::new();
let mut this_status = DiffStatus::Good;
let mut message = None;
2023-04-21 22:33:10 -04:00
2023-09-06 12:08:06 -04:00
let key = unquote(
get_property(emacs, ":key")?
.ok_or("Emacs keywords should have a :key")?
.as_atom()?,
)?;
if key != rust.key.to_uppercase() {
this_status = DiffStatus::Bad;
message = Some(format!(
"Mismatchs keyword keys (emacs != rust) {:?} != {:?}",
key, rust.key
))
}
let value = unquote(
get_property(emacs, ":value")?
.ok_or("Emacs keywords should have a :value")?
.as_atom()?,
)?;
if value != rust.value {
this_status = DiffStatus::Bad;
message = Some(format!(
"Mismatchs keyword values (emacs != rust) {:?} != {:?}",
value, rust.value
))
}
2023-09-06 18:04:53 -04:00
Ok(DiffResult {
status: this_status,
name: rust.get_elisp_name(),
2023-09-06 18:04:53 -04:00
message,
children: child_status,
rust_source: rust.get_source(),
emacs_token: emacs,
}
.into())
}
fn compare_babel_call<'b, 's>(
_source: &'s str,
2023-09-06 18:04:53 -04:00
emacs: &'s Token<'s>,
rust: &'s BabelCall<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
2023-09-06 18:04:53 -04:00
let child_status = Vec::new();
let mut this_status = DiffStatus::Good;
let mut message = None;
// TODO: Compare :call :inside-header :arguments :end-header
2023-09-06 18:04:53 -04:00
let value = unquote(
get_property(emacs, ":value")?
.ok_or("Emacs keywords should have a :value")?
.as_atom()?,
)?;
if value != rust.value {
this_status = DiffStatus::Bad;
message = Some(format!(
"Mismatchs keyword values (emacs != rust) {:?} != {:?}",
value, rust.value
))
}
2023-04-21 22:33:10 -04:00
Ok(DiffResult {
status: this_status,
name: rust.get_elisp_name(),
message,
2023-04-21 22:33:10 -04:00
children: child_status,
rust_source: rust.get_source(),
emacs_token: emacs,
}
.into())
2023-04-21 22:33:10 -04:00
}
2023-04-22 16:56:36 -04:00
fn compare_latex_environment<'b, 's>(
_source: &'s str,
2023-04-22 16:56:36 -04:00
emacs: &'s Token<'s>,
rust: &'s LatexEnvironment<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
2023-04-22 16:56:36 -04:00
let child_status = Vec::new();
let this_status = DiffStatus::Good;
let message = None;
2023-04-22 16:56:36 -04:00
// TODO: Compare :value
2023-04-22 16:56:36 -04:00
Ok(DiffResult {
status: this_status,
name: rust.get_elisp_name(),
message,
2023-04-22 16:56:36 -04:00
children: child_status,
rust_source: rust.get_source(),
emacs_token: emacs,
}
.into())
2023-04-22 16:56:36 -04:00
}
fn compare_plain_text<'b, 's>(
_source: &'s str,
emacs: &'s Token<'s>,
rust: &'s PlainText<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
let mut this_status = DiffStatus::Good;
let mut message = None;
let rust_source = rust.get_source();
let text = emacs.as_text()?;
let start_ind: usize = text
.properties
.get(0)
.expect("Should have start index.")
.as_atom()?
.parse()?;
let end_ind: usize = text
.properties
.get(1)
.expect("Should have end index.")
.as_atom()?
.parse()?;
let emacs_text_length = end_ind - start_ind;
if rust_source.chars().count() != emacs_text_length {
this_status = DiffStatus::Bad;
message = Some(format!(
"(emacs len != rust len) {:?} != {:?}",
emacs_text_length,
rust_source.len()
));
}
2023-08-25 06:46:00 -04:00
let unquoted_text = unquote(text.text)?;
if unquoted_text != rust_source {
this_status = DiffStatus::Bad;
message = Some(format!(
"(emacs != rust) {:?} != {:?}",
unquoted_text, rust_source
));
}
Ok(DiffResult {
status: this_status,
name: rust.get_elisp_name(),
message,
children: Vec::new(),
rust_source,
emacs_token: emacs,
}
.into())
}
fn compare_bold<'b, 's>(
_source: &'s str,
emacs: &'s Token<'s>,
rust: &'s Bold<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
let this_status = DiffStatus::Good;
let message = None;
2023-04-22 20:48:01 -04:00
Ok(DiffResult {
2023-04-22 20:48:01 -04:00
status: this_status,
name: rust.get_elisp_name(),
message,
children: Vec::new(),
rust_source: rust.get_source(),
emacs_token: emacs,
}
.into())
}
fn compare_italic<'b, 's>(
_source: &'s str,
emacs: &'s Token<'s>,
rust: &'s Italic<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
let this_status = DiffStatus::Good;
let message = None;
2023-04-22 20:48:01 -04:00
Ok(DiffResult {
2023-04-22 20:48:01 -04:00
status: this_status,
name: rust.get_elisp_name(),
message,
children: Vec::new(),
rust_source: rust.get_source(),
emacs_token: emacs,
}
.into())
}
fn compare_underline<'b, 's>(
_source: &'s str,
emacs: &'s Token<'s>,
rust: &'s Underline<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
let this_status = DiffStatus::Good;
let message = None;
2023-04-22 20:48:01 -04:00
Ok(DiffResult {
2023-04-22 20:48:01 -04:00
status: this_status,
name: rust.get_elisp_name(),
message,
children: Vec::new(),
rust_source: rust.get_source(),
emacs_token: emacs,
}
.into())
}
fn compare_verbatim<'b, 's>(
_source: &'s str,
emacs: &'s Token<'s>,
rust: &'s Verbatim<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
let this_status = DiffStatus::Good;
let message = None;
2023-04-22 20:48:01 -04:00
// TODO: Compare :value
Ok(DiffResult {
2023-04-22 20:48:01 -04:00
status: this_status,
name: rust.get_elisp_name(),
message,
children: Vec::new(),
rust_source: rust.get_source(),
emacs_token: emacs,
}
.into())
}
fn compare_code<'b, 's>(
_source: &'s str,
emacs: &'s Token<'s>,
rust: &'s Code<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
let this_status = DiffStatus::Good;
let message = None;
2023-04-22 20:48:01 -04:00
// TODO: Compare :value
Ok(DiffResult {
2023-04-22 20:48:01 -04:00
status: this_status,
name: rust.get_elisp_name(),
message,
children: Vec::new(),
rust_source: rust.get_source(),
emacs_token: emacs,
}
.into())
}
fn compare_strike_through<'b, 's>(
_source: &'s str,
emacs: &'s Token<'s>,
rust: &'s StrikeThrough<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
let this_status = DiffStatus::Good;
let message = None;
2023-04-22 20:48:01 -04:00
Ok(DiffResult {
2023-04-22 20:48:01 -04:00
status: this_status,
name: rust.get_elisp_name(),
message,
children: Vec::new(),
rust_source: rust.get_source(),
emacs_token: emacs,
}
.into())
}
fn compare_regular_link<'b, 's>(
_source: &'s str,
emacs: &'s Token<'s>,
rust: &'s RegularLink<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
let this_status = DiffStatus::Good;
let message = None;
// TODO: Compare :type :path :format :raw-link :application :search-option
Ok(DiffResult {
status: this_status,
name: rust.get_elisp_name(),
message,
children: Vec::new(),
rust_source: rust.get_source(),
emacs_token: emacs,
}
.into())
}
fn compare_radio_link<'b, 's>(
_source: &'s str,
emacs: &'s Token<'s>,
rust: &'s RadioLink<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
let this_status = DiffStatus::Good;
let message = None;
// TODO: Compare :type :path :format :raw-link :application :search-option
Ok(DiffResult {
status: this_status,
name: rust.get_elisp_name(),
message,
children: Vec::new(),
rust_source: rust.get_source(),
emacs_token: emacs,
}
.into())
}
fn compare_radio_target<'b, 's>(
_source: &'s str,
emacs: &'s Token<'s>,
rust: &'s RadioTarget<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
let this_status = DiffStatus::Good;
let message = None;
// TODO: Compare :value
Ok(DiffResult {
status: this_status,
name: rust.get_elisp_name(),
message,
children: Vec::new(),
rust_source: rust.get_source(),
emacs_token: emacs,
}
.into())
}
2023-07-13 18:18:07 -04:00
fn compare_plain_link<'b, 's>(
_source: &'s str,
2023-07-13 18:18:07 -04:00
emacs: &'s Token<'s>,
rust: &'s PlainLink<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
let this_status = DiffStatus::Good;
let message = None;
2023-07-13 18:18:07 -04:00
// TODO: Compare :type :path :format :raw-link :application :search-option
2023-07-13 18:18:07 -04:00
Ok(DiffResult {
status: this_status,
name: rust.get_elisp_name(),
message,
2023-07-13 18:18:07 -04:00
children: Vec::new(),
rust_source: rust.get_source(),
emacs_token: emacs,
}
.into())
2023-07-13 18:18:07 -04:00
}
2023-07-13 22:42:42 -04:00
fn compare_angle_link<'b, 's>(
_source: &'s str,
2023-07-13 22:42:42 -04:00
emacs: &'s Token<'s>,
rust: &'s AngleLink<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
let this_status = DiffStatus::Good;
let message = None;
2023-07-13 22:42:42 -04:00
// TODO: Compare :type :path :format :raw-link :application :search-option
2023-07-13 22:42:42 -04:00
Ok(DiffResult {
status: this_status,
name: rust.get_elisp_name(),
message,
2023-07-13 22:42:42 -04:00
children: Vec::new(),
rust_source: rust.get_source(),
emacs_token: emacs,
}
.into())
2023-07-13 22:42:42 -04:00
}
2023-07-13 23:26:51 -04:00
fn compare_org_macro<'b, 's>(
_source: &'s str,
2023-07-13 23:26:51 -04:00
emacs: &'s Token<'s>,
rust: &'s OrgMacro<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
let this_status = DiffStatus::Good;
let message = None;
2023-07-13 23:26:51 -04:00
// TODO: Compare :key :value :args
2023-07-13 23:26:51 -04:00
Ok(DiffResult {
status: this_status,
name: rust.get_elisp_name(),
message,
2023-07-13 23:26:51 -04:00
children: Vec::new(),
rust_source: rust.get_source(),
emacs_token: emacs,
}
.into())
2023-07-13 23:26:51 -04:00
}
2023-07-18 20:05:39 -04:00
fn compare_entity<'b, 's>(
_source: &'s str,
2023-07-18 20:05:39 -04:00
emacs: &'s Token<'s>,
rust: &'s Entity<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
let this_status = DiffStatus::Good;
let message = None;
2023-07-18 20:05:39 -04:00
// TODO: Compare :name :latex :latex-math-p :html :ascii :latin1 :utf-8 :use-brackets-p
2023-07-18 20:05:39 -04:00
Ok(DiffResult {
status: this_status,
name: rust.get_elisp_name(),
message,
2023-07-18 20:05:39 -04:00
children: Vec::new(),
rust_source: rust.get_source(),
emacs_token: emacs,
}
.into())
2023-07-18 20:05:39 -04:00
}
2023-07-18 20:51:06 -04:00
fn compare_latex_fragment<'b, 's>(
_source: &'s str,
2023-07-18 20:51:06 -04:00
emacs: &'s Token<'s>,
rust: &'s LatexFragment<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
let this_status = DiffStatus::Good;
let message = None;
2023-07-18 20:51:06 -04:00
// TODO: Compare :value
2023-07-18 20:51:06 -04:00
Ok(DiffResult {
status: this_status,
name: rust.get_elisp_name(),
message,
2023-07-18 20:51:06 -04:00
children: Vec::new(),
rust_source: rust.get_source(),
emacs_token: emacs,
}
.into())
2023-07-18 20:51:06 -04:00
}
2023-07-19 00:09:16 -04:00
fn compare_export_snippet<'b, 's>(
_source: &'s str,
2023-07-19 00:09:16 -04:00
emacs: &'s Token<'s>,
rust: &'s ExportSnippet<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
let this_status = DiffStatus::Good;
let message = None;
2023-07-19 00:09:16 -04:00
// TODO: Compare :back-end :value
2023-07-19 00:09:16 -04:00
Ok(DiffResult {
status: this_status,
name: rust.get_elisp_name(),
message,
2023-07-19 00:09:16 -04:00
children: Vec::new(),
rust_source: rust.get_source(),
emacs_token: emacs,
}
.into())
2023-07-19 00:09:16 -04:00
}
fn compare_footnote_reference<'b, 's>(
_source: &'s str,
emacs: &'s Token<'s>,
rust: &'s FootnoteReference<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
let this_status = DiffStatus::Good;
let message = None;
// TODO: Compare :label :type
Ok(DiffResult {
status: this_status,
name: rust.get_elisp_name(),
message,
children: Vec::new(),
rust_source: rust.get_source(),
emacs_token: emacs,
}
.into())
}
2023-07-20 00:38:16 -04:00
fn compare_citation<'b, 's>(
_source: &'s str,
2023-07-20 00:38:16 -04:00
emacs: &'s Token<'s>,
rust: &'s Citation<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
let this_status = DiffStatus::Good;
let message = None;
2023-07-20 00:38:16 -04:00
// TODO: Compare :style :prefix :suffix
2023-07-20 00:38:16 -04:00
Ok(DiffResult {
status: this_status,
name: rust.get_elisp_name(),
message,
2023-07-20 00:38:16 -04:00
children: Vec::new(),
rust_source: rust.get_source(),
emacs_token: emacs,
}
.into())
2023-07-20 00:38:16 -04:00
}
fn compare_citation_reference<'b, 's>(
_source: &'s str,
2023-07-20 00:38:16 -04:00
emacs: &'s Token<'s>,
rust: &'s CitationReference<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
let this_status = DiffStatus::Good;
let message = None;
2023-07-20 00:38:16 -04:00
// TODO: Compare :key :prefix :suffix
2023-07-20 00:38:16 -04:00
Ok(DiffResult {
status: this_status,
name: rust.get_elisp_name(),
message,
2023-07-20 00:38:16 -04:00
children: Vec::new(),
rust_source: rust.get_source(),
emacs_token: emacs,
}
.into())
2023-07-20 00:38:16 -04:00
}
fn compare_inline_babel_call<'b, 's>(
_source: &'s str,
emacs: &'s Token<'s>,
rust: &'s InlineBabelCall<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
let this_status = DiffStatus::Good;
let message = None;
// TODO: Compare :call :inside-header :arguments :end-header :value
Ok(DiffResult {
status: this_status,
name: rust.get_elisp_name(),
message,
children: Vec::new(),
rust_source: rust.get_source(),
emacs_token: emacs,
}
.into())
}
fn compare_inline_source_block<'b, 's>(
_source: &'s str,
emacs: &'s Token<'s>,
rust: &'s InlineSourceBlock<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
let this_status = DiffStatus::Good;
let message = None;
// TODO: Compare :language :value :parameters
Ok(DiffResult {
status: this_status,
name: rust.get_elisp_name(),
message,
children: Vec::new(),
rust_source: rust.get_source(),
emacs_token: emacs,
}
.into())
}
2023-07-21 23:48:37 -04:00
fn compare_line_break<'b, 's>(
_source: &'s str,
2023-07-21 23:48:37 -04:00
emacs: &'s Token<'s>,
rust: &'s LineBreak<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
let this_status = DiffStatus::Good;
let message = None;
2023-07-21 23:48:37 -04:00
Ok(DiffResult {
status: this_status,
name: rust.get_elisp_name(),
message,
2023-07-21 23:48:37 -04:00
children: Vec::new(),
rust_source: rust.get_source(),
emacs_token: emacs,
}
.into())
2023-07-21 23:48:37 -04:00
}
2023-07-22 01:15:04 -04:00
fn compare_target<'b, 's>(
_source: &'s str,
2023-07-22 01:15:04 -04:00
emacs: &'s Token<'s>,
rust: &'s Target<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
let this_status = DiffStatus::Good;
let message = None;
2023-07-22 01:15:04 -04:00
// TODO: Compare :value
2023-07-22 01:15:04 -04:00
Ok(DiffResult {
status: this_status,
name: rust.get_elisp_name(),
message,
2023-07-22 01:15:04 -04:00
children: Vec::new(),
rust_source: rust.get_source(),
emacs_token: emacs,
}
.into())
2023-07-22 01:15:04 -04:00
}
fn compare_statistics_cookie<'b, 's>(
_source: &'s str,
emacs: &'s Token<'s>,
rust: &'s StatisticsCookie<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
let this_status = DiffStatus::Good;
let message = None;
// TODO: Compare :value
Ok(DiffResult {
status: this_status,
name: rust.get_elisp_name(),
message,
children: Vec::new(),
rust_source: rust.get_source(),
emacs_token: emacs,
}
.into())
}
fn compare_subscript<'b, 's>(
_source: &'s str,
emacs: &'s Token<'s>,
rust: &'s Subscript<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
let this_status = DiffStatus::Good;
let message = None;
// TODO: Compare :use-brackets-p
Ok(DiffResult {
status: this_status,
name: rust.get_elisp_name(),
message,
children: Vec::new(),
rust_source: rust.get_source(),
emacs_token: emacs,
}
.into())
}
fn compare_superscript<'b, 's>(
_source: &'s str,
emacs: &'s Token<'s>,
rust: &'s Superscript<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
let this_status = DiffStatus::Good;
let message = None;
// TODO: Compare :use-brackets-p
Ok(DiffResult {
status: this_status,
name: rust.get_elisp_name(),
message,
children: Vec::new(),
rust_source: rust.get_source(),
emacs_token: emacs,
}
.into())
}
2023-07-24 17:34:07 -04:00
fn compare_timestamp<'b, 's>(
_source: &'s str,
emacs: &'b Token<'s>,
rust: &'b Timestamp<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
let this_status = DiffStatus::Good;
let message = None;
2023-07-24 17:34:07 -04:00
// TODO: Compare :type :range-type :raw-value :year-start :month-start :day-start :hour-start :minute-start :year-end :month-end :day-end :hour-end :minute-end
2023-07-24 17:34:07 -04:00
Ok(DiffResult {
status: this_status,
name: rust.get_elisp_name(),
message,
2023-07-24 17:34:07 -04:00
children: Vec::new(),
rust_source: rust.get_source(),
emacs_token: emacs,
}
.into())
2023-07-24 17:34:07 -04:00
}