2023-04-19 15:29:46 -04:00
|
|
|
use super::util::assert_bounds;
|
2023-04-19 15:19:21 -04:00
|
|
|
use super::util::assert_name;
|
2023-04-21 20:32:51 -04:00
|
|
|
use crate::parser::sexp::Token;
|
2023-04-22 20:22:07 -04:00
|
|
|
use crate::parser::Bold;
|
2023-04-21 19:02:16 -04:00
|
|
|
use crate::parser::Clock;
|
2023-04-22 20:22:07 -04:00
|
|
|
use crate::parser::Code;
|
2023-04-15 16:53:58 -04:00
|
|
|
use crate::parser::Comment;
|
2023-04-21 17:40:49 -04:00
|
|
|
use crate::parser::CommentBlock;
|
2023-04-21 20:22:31 -04:00
|
|
|
use crate::parser::DiarySexp;
|
2023-04-11 17:35:09 -04:00
|
|
|
use crate::parser::Document;
|
2023-04-12 11:35:02 -04:00
|
|
|
use crate::parser::DocumentElement;
|
2023-04-19 13:30:15 -04:00
|
|
|
use crate::parser::Drawer;
|
2023-04-21 18:57:38 -04:00
|
|
|
use crate::parser::DynamicBlock;
|
2023-04-12 13:16:25 -04:00
|
|
|
use crate::parser::Element;
|
2023-04-21 17:40:49 -04:00
|
|
|
use crate::parser::ExampleBlock;
|
|
|
|
use crate::parser::ExportBlock;
|
2023-04-21 22:04:22 -04:00
|
|
|
use crate::parser::FixedWidthArea;
|
2023-04-12 13:45:22 -04:00
|
|
|
use crate::parser::FootnoteDefinition;
|
|
|
|
use crate::parser::GreaterBlock;
|
2023-04-11 19:16:04 -04:00
|
|
|
use crate::parser::Heading;
|
2023-04-21 22:23:59 -04:00
|
|
|
use crate::parser::HorizontalRule;
|
2023-04-22 20:22:07 -04:00
|
|
|
use crate::parser::Italic;
|
2023-04-21 22:33:10 -04:00
|
|
|
use crate::parser::Keyword;
|
2023-04-22 16:56:36 -04:00
|
|
|
use crate::parser::LatexEnvironment;
|
2023-04-22 17:58:16 -04:00
|
|
|
use crate::parser::Object;
|
2023-04-12 11:46:49 -04:00
|
|
|
use crate::parser::Paragraph;
|
2023-04-12 13:16:25 -04:00
|
|
|
use crate::parser::PlainList;
|
2023-04-12 14:07:33 -04:00
|
|
|
use crate::parser::PlainListItem;
|
2023-04-22 17:58:16 -04:00
|
|
|
use crate::parser::PlainText;
|
2023-04-21 21:33:23 -04:00
|
|
|
use crate::parser::Planning;
|
2023-04-19 16:51:00 -04:00
|
|
|
use crate::parser::PropertyDrawer;
|
2023-04-22 17:58:16 -04:00
|
|
|
use crate::parser::RegularLink;
|
2023-04-12 13:16:25 -04:00
|
|
|
use crate::parser::Section;
|
2023-04-21 17:40:49 -04:00
|
|
|
use crate::parser::SrcBlock;
|
2023-04-22 20:22:07 -04:00
|
|
|
use crate::parser::StrikeThrough;
|
2023-04-19 20:59:58 -04:00
|
|
|
use crate::parser::Table;
|
2023-04-21 15:45:35 -04:00
|
|
|
use crate::parser::TableCell;
|
|
|
|
use crate::parser::TableRow;
|
2023-04-22 20:22:07 -04:00
|
|
|
use crate::parser::Underline;
|
|
|
|
use crate::parser::Verbatim;
|
2023-04-21 17:40:49 -04:00
|
|
|
use crate::parser::VerseBlock;
|
2023-04-11 17:35:09 -04:00
|
|
|
|
2023-04-11 18:27:01 -04:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct DiffResult {
|
|
|
|
status: DiffStatus,
|
|
|
|
name: String,
|
2023-04-21 18:22:17 -04:00
|
|
|
#[allow(dead_code)]
|
2023-04-19 15:19:21 -04:00
|
|
|
message: Option<String>,
|
2023-04-11 18:27:01 -04:00
|
|
|
children: Vec<DiffResult>,
|
|
|
|
}
|
|
|
|
|
2023-04-11 19:22:42 -04:00
|
|
|
#[derive(Debug, PartialEq)]
|
2023-04-11 18:27:01 -04:00
|
|
|
pub enum DiffStatus {
|
|
|
|
Good,
|
|
|
|
Bad,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl DiffResult {
|
|
|
|
pub fn print(&self) -> Result<(), Box<dyn std::error::Error>> {
|
|
|
|
self.print_indented(0)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn print_indented(&self, indentation: usize) -> 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() {
|
|
|
|
"BADCHILD"
|
|
|
|
} else {
|
|
|
|
"GOOD"
|
|
|
|
}
|
2023-04-12 11:35:02 -04:00
|
|
|
}
|
2023-04-11 19:22:42 -04:00
|
|
|
DiffStatus::Bad => "BAD",
|
|
|
|
}
|
|
|
|
};
|
2023-04-22 17:58:16 -04:00
|
|
|
println!(
|
|
|
|
"{}{} {} {}",
|
|
|
|
" ".repeat(indentation),
|
|
|
|
status_text,
|
|
|
|
self.name,
|
|
|
|
self.message.as_ref().map(|m| m.as_str()).unwrap_or("")
|
|
|
|
);
|
2023-04-11 18:27:01 -04:00
|
|
|
for child in self.children.iter() {
|
|
|
|
child.print_indented(indentation + 1)?;
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
2023-04-11 19:22:42 -04:00
|
|
|
|
|
|
|
pub fn has_bad_children(&self) -> bool {
|
2023-04-12 11:35:02 -04:00
|
|
|
self.children
|
|
|
|
.iter()
|
|
|
|
.any(|child| child.status == DiffStatus::Bad || child.has_bad_children())
|
2023-04-11 19:22:42 -04:00
|
|
|
}
|
2023-04-12 14:50:56 -04:00
|
|
|
|
|
|
|
pub fn is_bad(&self) -> bool {
|
|
|
|
match self.status {
|
2023-04-12 15:03:14 -04:00
|
|
|
DiffStatus::Good => self.has_bad_children(),
|
2023-04-12 14:50:56 -04:00
|
|
|
DiffStatus::Bad => true,
|
|
|
|
}
|
|
|
|
}
|
2023-04-11 17:35:09 -04:00
|
|
|
}
|
|
|
|
|
2023-04-22 17:58:16 -04:00
|
|
|
fn compare_element<'s>(
|
|
|
|
source: &'s str,
|
|
|
|
emacs: &'s Token<'s>,
|
|
|
|
rust: &'s Element<'s>,
|
|
|
|
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
|
|
|
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),
|
|
|
|
Element::LatexEnvironment(obj) => compare_latex_environment(source, emacs, obj),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn compare_object<'s>(
|
|
|
|
source: &'s str,
|
|
|
|
emacs: &'s Token<'s>,
|
|
|
|
rust: &'s Object<'s>,
|
|
|
|
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
|
|
|
match rust {
|
2023-04-22 20:22:07 -04:00
|
|
|
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),
|
2023-04-22 17:58:16 -04:00
|
|
|
Object::PlainText(obj) => compare_plain_text(source, emacs, obj),
|
|
|
|
Object::RegularLink(obj) => compare_regular_link(source, emacs, obj),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-11 18:27:01 -04:00
|
|
|
pub fn compare_document<'s>(
|
2023-04-11 17:35:09 -04:00
|
|
|
emacs: &'s Token<'s>,
|
|
|
|
rust: &'s Document<'s>,
|
2023-04-11 18:27:01 -04:00
|
|
|
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
2023-04-11 17:35:09 -04:00
|
|
|
let children = emacs.as_list()?;
|
2023-04-11 18:27:01 -04:00
|
|
|
let mut child_status = Vec::new();
|
2023-04-11 19:16:04 -04:00
|
|
|
let mut this_status = DiffStatus::Good;
|
2023-04-19 16:04:30 -04:00
|
|
|
let emacs_name = "org-data";
|
|
|
|
if assert_name(emacs, emacs_name).is_err() {
|
2023-04-19 15:38:36 -04:00
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
}
|
2023-04-11 17:35:09 -04:00
|
|
|
|
2023-04-11 18:27:01 -04:00
|
|
|
// Skipping "org-data" and the first parameter which is often nil
|
|
|
|
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(
|
2023-04-11 18:34:11 -04:00
|
|
|
rust.source,
|
2023-04-11 18:27:01 -04:00
|
|
|
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.")?;
|
2023-04-11 19:16:04 -04:00
|
|
|
child_status.push(compare_heading(rust.source, token, corresponding_heading)?);
|
2023-04-11 18:27:01 -04:00
|
|
|
} else {
|
|
|
|
return Err("Document should only contain sections and headlines.".into());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(DiffResult {
|
2023-04-11 19:16:04 -04:00
|
|
|
status: this_status,
|
2023-04-19 16:04:30 -04:00
|
|
|
name: emacs_name.to_owned(),
|
2023-04-19 15:19:21 -04:00
|
|
|
message: None,
|
2023-04-11 18:27:01 -04:00
|
|
|
children: child_status,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-04-12 13:16:25 -04:00
|
|
|
fn compare_section<'s>(
|
2023-04-11 18:34:11 -04:00
|
|
|
source: &'s str,
|
2023-04-11 18:27:01 -04:00
|
|
|
emacs: &'s Token<'s>,
|
|
|
|
rust: &'s Section<'s>,
|
|
|
|
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
|
|
|
let children = emacs.as_list()?;
|
2023-04-11 19:16:04 -04:00
|
|
|
let mut this_status = DiffStatus::Good;
|
2023-04-19 15:38:36 -04:00
|
|
|
let mut child_status = Vec::new();
|
2023-04-19 16:04:30 -04:00
|
|
|
let emacs_name = "section";
|
|
|
|
if assert_name(emacs, emacs_name).is_err() {
|
2023-04-19 15:38:36 -04:00
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
}
|
2023-04-11 19:16:04 -04:00
|
|
|
|
2023-04-19 15:29:46 -04:00
|
|
|
if assert_bounds(source, emacs, rust).is_err() {
|
2023-04-11 19:16:04 -04:00
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
}
|
2023-04-11 18:27:01 -04:00
|
|
|
|
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)?);
|
|
|
|
}
|
|
|
|
|
2023-04-11 18:27:01 -04:00
|
|
|
Ok(DiffResult {
|
2023-04-11 19:16:04 -04:00
|
|
|
status: this_status,
|
2023-04-19 16:04:30 -04:00
|
|
|
name: emacs_name.to_owned(),
|
2023-04-19 15:19:21 -04:00
|
|
|
message: None,
|
2023-04-11 18:27:01 -04:00
|
|
|
children: child_status,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-04-12 13:16:25 -04:00
|
|
|
fn compare_heading<'s>(
|
2023-04-11 18:34:11 -04:00
|
|
|
source: &'s str,
|
2023-04-11 18:27:01 -04:00
|
|
|
emacs: &'s Token<'s>,
|
2023-04-11 19:16:04 -04:00
|
|
|
rust: &'s Heading<'s>,
|
2023-04-11 18:27:01 -04:00
|
|
|
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
|
|
|
let children = emacs.as_list()?;
|
|
|
|
let mut child_status = Vec::new();
|
2023-04-11 19:16:04 -04:00
|
|
|
let mut this_status = DiffStatus::Good;
|
2023-04-19 16:04:30 -04:00
|
|
|
let emacs_name = "headline";
|
|
|
|
if assert_name(emacs, emacs_name).is_err() {
|
2023-04-19 15:38:36 -04:00
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
}
|
2023-04-11 19:16:04 -04:00
|
|
|
|
2023-04-19 15:29:46 -04:00
|
|
|
if assert_bounds(source, emacs, rust).is_err() {
|
2023-04-11 19:16:04 -04:00
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
}
|
2023-04-11 18:27:01 -04:00
|
|
|
|
2023-04-22 22:56:36 -04:00
|
|
|
let title = {
|
|
|
|
let children = emacs.as_list()?;
|
|
|
|
let attributes_child = children
|
|
|
|
.iter()
|
|
|
|
.nth(1)
|
|
|
|
.ok_or("Should have an attributes child.")?;
|
|
|
|
let attributes_map = attributes_child.as_map()?;
|
|
|
|
let title = attributes_map
|
|
|
|
.get(":title")
|
|
|
|
.ok_or("Missing :title attribute.");
|
|
|
|
*title?
|
|
|
|
};
|
|
|
|
for (emacs_child, rust_child) in title.as_list()?.iter().zip(rust.title.iter()) {
|
|
|
|
child_status.push(compare_object(source, emacs_child, rust_child)?);
|
|
|
|
}
|
|
|
|
|
2023-04-12 11:35:02 -04:00
|
|
|
for (emacs_child, rust_child) in children.iter().skip(2).zip(rust.children.iter()) {
|
|
|
|
match rust_child {
|
|
|
|
DocumentElement::Heading(rust_heading) => {
|
|
|
|
child_status.push(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) => {
|
|
|
|
child_status.push(compare_section(source, emacs_child, rust_section)?);
|
2023-04-12 13:16:25 -04:00
|
|
|
}
|
2023-04-12 11:35:02 -04:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-04-11 18:27:01 -04:00
|
|
|
Ok(DiffResult {
|
2023-04-11 19:16:04 -04:00
|
|
|
status: this_status,
|
2023-04-19 16:04:30 -04:00
|
|
|
name: emacs_name.to_owned(),
|
2023-04-19 15:19:21 -04:00
|
|
|
message: None,
|
2023-04-11 18:27:01 -04:00
|
|
|
children: child_status,
|
|
|
|
})
|
2023-04-11 17:35:09 -04:00
|
|
|
}
|
2023-04-12 11:46:49 -04:00
|
|
|
|
2023-04-12 13:16:25 -04:00
|
|
|
fn compare_paragraph<'s>(
|
2023-04-12 11:46:49 -04:00
|
|
|
source: &'s str,
|
|
|
|
emacs: &'s Token<'s>,
|
|
|
|
rust: &'s Paragraph<'s>,
|
|
|
|
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
|
|
|
let children = emacs.as_list()?;
|
2023-04-22 17:58:16 -04:00
|
|
|
let mut child_status = Vec::new();
|
2023-04-12 11:46:49 -04:00
|
|
|
let mut this_status = DiffStatus::Good;
|
2023-04-19 16:04:30 -04:00
|
|
|
let emacs_name = "paragraph";
|
|
|
|
if assert_name(emacs, emacs_name).is_err() {
|
2023-04-19 15:38:36 -04:00
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
}
|
2023-04-12 11:46:49 -04:00
|
|
|
|
2023-04-19 15:29:46 -04:00
|
|
|
if assert_bounds(source, emacs, rust).is_err() {
|
2023-04-12 11:46:49 -04:00
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
}
|
|
|
|
|
2023-04-22 17:58:16 -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,
|
2023-04-19 16:04:30 -04:00
|
|
|
name: emacs_name.to_owned(),
|
2023-04-19 15:19:21 -04:00
|
|
|
message: None,
|
2023-04-12 11:46:49 -04:00
|
|
|
children: child_status,
|
|
|
|
})
|
|
|
|
}
|
2023-04-12 13:16:25 -04:00
|
|
|
|
|
|
|
fn compare_plain_list<'s>(
|
|
|
|
source: &'s str,
|
|
|
|
emacs: &'s Token<'s>,
|
|
|
|
rust: &'s PlainList<'s>,
|
|
|
|
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
|
|
|
let children = emacs.as_list()?;
|
|
|
|
let mut child_status = Vec::new();
|
|
|
|
let mut this_status = DiffStatus::Good;
|
2023-04-19 16:04:30 -04:00
|
|
|
let emacs_name = "plain-list";
|
|
|
|
if assert_name(emacs, emacs_name).is_err() {
|
2023-04-19 15:38:36 -04:00
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
}
|
2023-04-12 13:16:25 -04:00
|
|
|
|
2023-04-19 15:29:46 -04:00
|
|
|
if assert_bounds(source, emacs, rust).is_err() {
|
2023-04-12 13:16:25 -04:00
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
}
|
|
|
|
|
2023-04-12 14:07:33 -04:00
|
|
|
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,
|
2023-04-19 16:04:30 -04:00
|
|
|
name: emacs_name.to_owned(),
|
2023-04-19 15:19:21 -04:00
|
|
|
message: None,
|
2023-04-12 13:16:25 -04:00
|
|
|
children: child_status,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-04-12 14:07:33 -04:00
|
|
|
fn compare_plain_list_item<'s>(
|
|
|
|
source: &'s str,
|
|
|
|
emacs: &'s Token<'s>,
|
|
|
|
rust: &'s PlainListItem<'s>,
|
|
|
|
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
|
|
|
let children = emacs.as_list()?;
|
|
|
|
let mut child_status = Vec::new();
|
|
|
|
let mut this_status = DiffStatus::Good;
|
2023-04-19 16:04:30 -04:00
|
|
|
let emacs_name = "item";
|
|
|
|
if assert_name(emacs, emacs_name).is_err() {
|
2023-04-19 15:38:36 -04:00
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
}
|
2023-04-12 14:07:33 -04:00
|
|
|
|
2023-04-19 15:29:46 -04:00
|
|
|
if assert_bounds(source, emacs, rust).is_err() {
|
2023-04-12 14:07:33 -04:00
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
2023-04-19 16:04:30 -04:00
|
|
|
name: emacs_name.to_owned(),
|
2023-04-19 15:19:21 -04:00
|
|
|
message: None,
|
2023-04-12 14:07:33 -04:00
|
|
|
children: child_status,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-04-12 13:45:22 -04:00
|
|
|
fn compare_greater_block<'s>(
|
|
|
|
source: &'s str,
|
|
|
|
emacs: &'s Token<'s>,
|
|
|
|
rust: &'s GreaterBlock<'s>,
|
|
|
|
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
|
|
|
let children = emacs.as_list()?;
|
2023-04-19 15:38:36 -04:00
|
|
|
let mut child_status = Vec::new();
|
|
|
|
let mut this_status = DiffStatus::Good;
|
2023-04-19 16:04:30 -04:00
|
|
|
let emacs_name = match rust.name.to_lowercase().as_str() {
|
|
|
|
"center" => "center-block",
|
|
|
|
"quote" => "quote-block",
|
|
|
|
_ => todo!(),
|
|
|
|
};
|
|
|
|
if assert_name(emacs, emacs_name).is_err() {
|
2023-04-19 15:38:36 -04:00
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
}
|
2023-04-12 13:45:22 -04:00
|
|
|
|
2023-04-19 15:29:46 -04:00
|
|
|
if assert_bounds(source, emacs, rust).is_err() {
|
2023-04-12 13:45:22 -04:00
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
2023-04-19 16:04:30 -04:00
|
|
|
name: emacs_name.to_owned(),
|
2023-04-19 15:19:21 -04:00
|
|
|
message: None,
|
2023-04-12 13:45:22 -04:00
|
|
|
children: child_status,
|
|
|
|
})
|
2023-04-19 13:59:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
fn compare_dynamic_block<'s>(
|
|
|
|
source: &'s str,
|
|
|
|
emacs: &'s Token<'s>,
|
|
|
|
rust: &'s DynamicBlock<'s>,
|
|
|
|
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
|
|
|
let children = emacs.as_list()?;
|
|
|
|
let mut child_status = Vec::new();
|
|
|
|
let mut this_status = DiffStatus::Good;
|
2023-04-19 15:38:36 -04:00
|
|
|
if assert_name(emacs, "dynamic-block").is_err() {
|
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
}
|
2023-04-19 13:59:17 -04:00
|
|
|
|
2023-04-19 15:29:46 -04:00
|
|
|
if assert_bounds(source, emacs, rust).is_err() {
|
2023-04-19 13:59:17 -04:00
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
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: "dynamic-block".to_owned(),
|
2023-04-19 15:19:21 -04:00
|
|
|
message: None,
|
2023-04-19 13:59:17 -04:00
|
|
|
children: child_status,
|
|
|
|
})
|
2023-04-12 13:45:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
fn compare_footnote_definition<'s>(
|
|
|
|
source: &'s str,
|
|
|
|
emacs: &'s Token<'s>,
|
|
|
|
rust: &'s FootnoteDefinition<'s>,
|
|
|
|
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
|
|
|
let children = emacs.as_list()?;
|
|
|
|
let mut child_status = Vec::new();
|
|
|
|
let mut this_status = DiffStatus::Good;
|
2023-04-19 16:04:30 -04:00
|
|
|
let emacs_name = "footnote-definition";
|
|
|
|
if assert_name(emacs, emacs_name).is_err() {
|
2023-04-19 15:38:36 -04:00
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
}
|
2023-04-12 13:45:22 -04:00
|
|
|
|
2023-04-19 15:29:46 -04:00
|
|
|
if assert_bounds(source, emacs, rust).is_err() {
|
2023-04-12 13:45:22 -04:00
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
2023-04-19 16:04:30 -04:00
|
|
|
name: emacs_name.to_owned(),
|
2023-04-19 15:19:21 -04:00
|
|
|
message: None,
|
2023-04-12 13:45:22 -04:00
|
|
|
children: child_status,
|
|
|
|
})
|
|
|
|
}
|
2023-04-15 16:53:58 -04:00
|
|
|
|
|
|
|
fn compare_comment<'s>(
|
|
|
|
source: &'s str,
|
|
|
|
emacs: &'s Token<'s>,
|
|
|
|
rust: &'s Comment<'s>,
|
|
|
|
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
2023-04-21 18:42:31 -04:00
|
|
|
let child_status = Vec::new();
|
2023-04-15 16:53:58 -04:00
|
|
|
let mut this_status = DiffStatus::Good;
|
2023-04-19 16:04:30 -04:00
|
|
|
let emacs_name = "comment";
|
|
|
|
if assert_name(emacs, emacs_name).is_err() {
|
2023-04-19 15:38:36 -04:00
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
}
|
2023-04-15 16:53:58 -04:00
|
|
|
|
2023-04-19 15:29:46 -04:00
|
|
|
if assert_bounds(source, emacs, rust).is_err() {
|
2023-04-15 16:53:58 -04:00
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(DiffResult {
|
|
|
|
status: this_status,
|
2023-04-19 16:04:30 -04:00
|
|
|
name: emacs_name.to_owned(),
|
2023-04-19 15:19:21 -04:00
|
|
|
message: None,
|
2023-04-15 16:53:58 -04:00
|
|
|
children: child_status,
|
|
|
|
})
|
|
|
|
}
|
2023-04-15 18:00:34 -04:00
|
|
|
|
|
|
|
fn compare_drawer<'s>(
|
|
|
|
source: &'s str,
|
|
|
|
emacs: &'s Token<'s>,
|
|
|
|
rust: &'s Drawer<'s>,
|
|
|
|
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
|
|
|
let children = emacs.as_list()?;
|
|
|
|
let mut child_status = Vec::new();
|
|
|
|
let mut this_status = DiffStatus::Good;
|
2023-04-19 16:04:30 -04:00
|
|
|
let emacs_name = "drawer";
|
|
|
|
if assert_name(emacs, emacs_name).is_err() {
|
2023-04-19 15:38:36 -04:00
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
}
|
2023-04-15 18:00:34 -04:00
|
|
|
|
2023-04-19 15:29:46 -04:00
|
|
|
if assert_bounds(source, emacs, rust).is_err() {
|
2023-04-15 18:00:34 -04:00
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
2023-04-19 16:04:30 -04:00
|
|
|
name: emacs_name.to_owned(),
|
2023-04-19 15:19:21 -04:00
|
|
|
message: None,
|
2023-04-15 18:00:34 -04:00
|
|
|
children: child_status,
|
|
|
|
})
|
|
|
|
}
|
2023-04-19 16:51:00 -04:00
|
|
|
|
|
|
|
fn compare_property_drawer<'s>(
|
|
|
|
source: &'s str,
|
|
|
|
emacs: &'s Token<'s>,
|
|
|
|
rust: &'s PropertyDrawer<'s>,
|
|
|
|
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
|
|
|
let children = emacs.as_list()?;
|
2023-04-21 18:42:31 -04:00
|
|
|
let child_status = Vec::new();
|
2023-04-19 16:51:00 -04:00
|
|
|
let mut this_status = DiffStatus::Good;
|
|
|
|
let emacs_name = "property-drawer";
|
|
|
|
if assert_name(emacs, emacs_name).is_err() {
|
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
if assert_bounds(source, emacs, rust).is_err() {
|
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
}
|
|
|
|
|
2023-04-21 18:42:31 -04:00
|
|
|
for (_emacs_child, _rust_child) in children.iter().skip(2).zip(rust.children.iter()) {
|
2023-04-19 16:51:00 -04:00
|
|
|
// TODO: What are node properties and are they the only legal child of property drawers?
|
|
|
|
// child_status.push(compare_element(source, emacs_child, rust_child)?);
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(DiffResult {
|
|
|
|
status: this_status,
|
|
|
|
name: emacs_name.to_owned(),
|
|
|
|
message: None,
|
|
|
|
children: child_status,
|
|
|
|
})
|
|
|
|
}
|
2023-04-19 20:59:58 -04:00
|
|
|
|
|
|
|
fn compare_table<'s>(
|
|
|
|
source: &'s str,
|
|
|
|
emacs: &'s Token<'s>,
|
|
|
|
rust: &'s Table<'s>,
|
|
|
|
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
|
|
|
let children = emacs.as_list()?;
|
|
|
|
let mut child_status = Vec::new();
|
|
|
|
let mut this_status = DiffStatus::Good;
|
|
|
|
let emacs_name = "table";
|
|
|
|
if assert_name(emacs, emacs_name).is_err() {
|
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
if assert_bounds(source, emacs, rust).is_err() {
|
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
}
|
|
|
|
|
2023-04-21 15:45:35 -04:00
|
|
|
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: emacs_name.to_owned(),
|
|
|
|
message: None,
|
|
|
|
children: child_status,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
fn compare_table_row<'s>(
|
|
|
|
source: &'s str,
|
|
|
|
emacs: &'s Token<'s>,
|
|
|
|
rust: &'s TableRow<'s>,
|
|
|
|
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
|
|
|
let children = emacs.as_list()?;
|
|
|
|
let mut child_status = Vec::new();
|
|
|
|
let mut this_status = DiffStatus::Good;
|
|
|
|
let emacs_name = "table-row";
|
|
|
|
if assert_name(emacs, emacs_name).is_err() {
|
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
if assert_bounds(source, emacs, rust).is_err() {
|
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
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: emacs_name.to_owned(),
|
|
|
|
message: None,
|
|
|
|
children: child_status,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
fn compare_table_cell<'s>(
|
|
|
|
source: &'s str,
|
|
|
|
emacs: &'s Token<'s>,
|
|
|
|
rust: &'s TableCell<'s>,
|
|
|
|
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
|
|
|
let children = emacs.as_list()?;
|
2023-04-21 18:42:31 -04:00
|
|
|
let child_status = Vec::new();
|
2023-04-21 15:45:35 -04:00
|
|
|
let mut this_status = DiffStatus::Good;
|
|
|
|
let emacs_name = "table-cell";
|
|
|
|
if assert_name(emacs, emacs_name).is_err() {
|
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
if assert_bounds(source, emacs, rust).is_err() {
|
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
}
|
|
|
|
|
2023-04-21 18:42:31 -04:00
|
|
|
for (_emacs_child, _rust_child) in children.iter().skip(2).zip(rust.children.iter()) {}
|
2023-04-21 15:45:35 -04:00
|
|
|
|
2023-04-19 20:59:58 -04:00
|
|
|
Ok(DiffResult {
|
|
|
|
status: this_status,
|
|
|
|
name: emacs_name.to_owned(),
|
|
|
|
message: None,
|
|
|
|
children: child_status,
|
|
|
|
})
|
|
|
|
}
|
2023-04-21 16:31:25 -04:00
|
|
|
|
2023-04-21 17:40:49 -04:00
|
|
|
fn compare_verse_block<'s>(
|
2023-04-21 16:31:25 -04:00
|
|
|
source: &'s str,
|
|
|
|
emacs: &'s Token<'s>,
|
2023-04-21 17:40:49 -04:00
|
|
|
rust: &'s VerseBlock<'s>,
|
|
|
|
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
2023-04-21 18:05:40 -04:00
|
|
|
let children = emacs.as_list()?;
|
2023-04-21 18:42:31 -04:00
|
|
|
let child_status = Vec::new();
|
2023-04-21 18:05:40 -04:00
|
|
|
let mut this_status = DiffStatus::Good;
|
|
|
|
let emacs_name = "verse-block";
|
|
|
|
if assert_name(emacs, emacs_name).is_err() {
|
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
if assert_bounds(source, emacs, rust).is_err() {
|
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
}
|
|
|
|
|
2023-04-21 18:42:31 -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: emacs_name.to_owned(),
|
|
|
|
message: None,
|
|
|
|
children: child_status,
|
|
|
|
})
|
2023-04-21 17:40:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
fn compare_comment_block<'s>(
|
|
|
|
source: &'s str,
|
|
|
|
emacs: &'s Token<'s>,
|
|
|
|
rust: &'s CommentBlock<'s>,
|
|
|
|
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
2023-04-21 18:05:40 -04:00
|
|
|
let mut this_status = DiffStatus::Good;
|
|
|
|
let emacs_name = "comment-block";
|
|
|
|
if assert_name(emacs, emacs_name).is_err() {
|
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
if assert_bounds(source, emacs, rust).is_err() {
|
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(DiffResult {
|
|
|
|
status: this_status,
|
|
|
|
name: emacs_name.to_owned(),
|
|
|
|
message: None,
|
|
|
|
children: Vec::new(),
|
|
|
|
})
|
2023-04-21 17:40:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
fn compare_example_block<'s>(
|
|
|
|
source: &'s str,
|
|
|
|
emacs: &'s Token<'s>,
|
|
|
|
rust: &'s ExampleBlock<'s>,
|
|
|
|
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
2023-04-21 18:05:40 -04:00
|
|
|
let mut this_status = DiffStatus::Good;
|
|
|
|
let emacs_name = "example-block";
|
|
|
|
if assert_name(emacs, emacs_name).is_err() {
|
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
if assert_bounds(source, emacs, rust).is_err() {
|
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(DiffResult {
|
|
|
|
status: this_status,
|
|
|
|
name: emacs_name.to_owned(),
|
|
|
|
message: None,
|
|
|
|
children: Vec::new(),
|
|
|
|
})
|
2023-04-21 17:40:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
fn compare_export_block<'s>(
|
|
|
|
source: &'s str,
|
|
|
|
emacs: &'s Token<'s>,
|
|
|
|
rust: &'s ExportBlock<'s>,
|
|
|
|
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
2023-04-21 18:05:40 -04:00
|
|
|
let mut this_status = DiffStatus::Good;
|
|
|
|
let emacs_name = "export-block";
|
|
|
|
if assert_name(emacs, emacs_name).is_err() {
|
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
if assert_bounds(source, emacs, rust).is_err() {
|
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(DiffResult {
|
|
|
|
status: this_status,
|
|
|
|
name: emacs_name.to_owned(),
|
|
|
|
message: None,
|
|
|
|
children: Vec::new(),
|
|
|
|
})
|
2023-04-21 17:40:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
fn compare_src_block<'s>(
|
|
|
|
source: &'s str,
|
|
|
|
emacs: &'s Token<'s>,
|
|
|
|
rust: &'s SrcBlock<'s>,
|
2023-04-21 16:31:25 -04:00
|
|
|
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
2023-04-21 18:05:40 -04:00
|
|
|
let mut this_status = DiffStatus::Good;
|
|
|
|
let emacs_name = "src-block";
|
|
|
|
if assert_name(emacs, emacs_name).is_err() {
|
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
if assert_bounds(source, emacs, rust).is_err() {
|
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(DiffResult {
|
|
|
|
status: this_status,
|
|
|
|
name: emacs_name.to_owned(),
|
|
|
|
message: None,
|
|
|
|
children: Vec::new(),
|
|
|
|
})
|
2023-04-21 16:31:25 -04:00
|
|
|
}
|
2023-04-21 19:02:16 -04:00
|
|
|
|
|
|
|
fn compare_clock<'s>(
|
|
|
|
source: &'s str,
|
|
|
|
emacs: &'s Token<'s>,
|
|
|
|
rust: &'s Clock<'s>,
|
|
|
|
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
|
|
|
let mut this_status = DiffStatus::Good;
|
|
|
|
let emacs_name = "clock";
|
|
|
|
if assert_name(emacs, emacs_name).is_err() {
|
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
if assert_bounds(source, emacs, rust).is_err() {
|
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(DiffResult {
|
|
|
|
status: this_status,
|
|
|
|
name: emacs_name.to_owned(),
|
|
|
|
message: None,
|
|
|
|
children: Vec::new(),
|
|
|
|
})
|
|
|
|
}
|
2023-04-21 20:22:31 -04:00
|
|
|
|
|
|
|
fn compare_diary_sexp<'s>(
|
|
|
|
source: &'s str,
|
|
|
|
emacs: &'s Token<'s>,
|
|
|
|
rust: &'s DiarySexp<'s>,
|
|
|
|
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
|
|
|
let mut this_status = DiffStatus::Good;
|
|
|
|
let emacs_name = "diary-sexp";
|
|
|
|
if assert_name(emacs, emacs_name).is_err() {
|
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
if assert_bounds(source, emacs, rust).is_err() {
|
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(DiffResult {
|
|
|
|
status: this_status,
|
|
|
|
name: emacs_name.to_owned(),
|
|
|
|
message: None,
|
|
|
|
children: Vec::new(),
|
|
|
|
})
|
|
|
|
}
|
2023-04-21 21:33:23 -04:00
|
|
|
|
|
|
|
fn compare_planning<'s>(
|
|
|
|
source: &'s str,
|
|
|
|
emacs: &'s Token<'s>,
|
|
|
|
rust: &'s Planning<'s>,
|
|
|
|
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
|
|
|
let mut this_status = DiffStatus::Good;
|
|
|
|
let emacs_name = "planning";
|
|
|
|
if assert_name(emacs, emacs_name).is_err() {
|
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
if assert_bounds(source, emacs, rust).is_err() {
|
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(DiffResult {
|
|
|
|
status: this_status,
|
|
|
|
name: emacs_name.to_owned(),
|
|
|
|
message: None,
|
|
|
|
children: Vec::new(),
|
|
|
|
})
|
|
|
|
}
|
2023-04-21 22:04:22 -04:00
|
|
|
|
|
|
|
fn compare_fixed_width_area<'s>(
|
|
|
|
source: &'s str,
|
|
|
|
emacs: &'s Token<'s>,
|
|
|
|
rust: &'s FixedWidthArea<'s>,
|
|
|
|
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
|
|
|
let child_status = Vec::new();
|
|
|
|
let mut this_status = DiffStatus::Good;
|
|
|
|
let emacs_name = "fixed-width";
|
|
|
|
if assert_name(emacs, emacs_name).is_err() {
|
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
if assert_bounds(source, emacs, rust).is_err() {
|
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(DiffResult {
|
|
|
|
status: this_status,
|
|
|
|
name: emacs_name.to_owned(),
|
|
|
|
message: None,
|
|
|
|
children: child_status,
|
|
|
|
})
|
|
|
|
}
|
2023-04-21 22:23:59 -04:00
|
|
|
|
|
|
|
fn compare_horizontal_rule<'s>(
|
|
|
|
source: &'s str,
|
|
|
|
emacs: &'s Token<'s>,
|
|
|
|
rust: &'s HorizontalRule<'s>,
|
|
|
|
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
|
|
|
let child_status = Vec::new();
|
|
|
|
let mut this_status = DiffStatus::Good;
|
|
|
|
let emacs_name = "horizontal-rule";
|
|
|
|
if assert_name(emacs, emacs_name).is_err() {
|
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
if assert_bounds(source, emacs, rust).is_err() {
|
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(DiffResult {
|
|
|
|
status: this_status,
|
|
|
|
name: emacs_name.to_owned(),
|
|
|
|
message: None,
|
|
|
|
children: child_status,
|
|
|
|
})
|
|
|
|
}
|
2023-04-21 22:33:10 -04:00
|
|
|
|
|
|
|
fn compare_keyword<'s>(
|
|
|
|
source: &'s str,
|
|
|
|
emacs: &'s Token<'s>,
|
|
|
|
rust: &'s Keyword<'s>,
|
|
|
|
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
|
|
|
let child_status = Vec::new();
|
|
|
|
let mut this_status = DiffStatus::Good;
|
|
|
|
let emacs_name = "keyword";
|
|
|
|
if assert_name(emacs, emacs_name).is_err() {
|
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
if assert_bounds(source, emacs, rust).is_err() {
|
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(DiffResult {
|
|
|
|
status: this_status,
|
|
|
|
name: emacs_name.to_owned(),
|
|
|
|
message: None,
|
|
|
|
children: child_status,
|
|
|
|
})
|
|
|
|
}
|
2023-04-22 16:56:36 -04:00
|
|
|
|
|
|
|
fn compare_latex_environment<'s>(
|
|
|
|
source: &'s str,
|
|
|
|
emacs: &'s Token<'s>,
|
|
|
|
rust: &'s LatexEnvironment<'s>,
|
|
|
|
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
|
|
|
let child_status = Vec::new();
|
|
|
|
let mut this_status = DiffStatus::Good;
|
|
|
|
let emacs_name = "latex-environment";
|
|
|
|
if assert_name(emacs, emacs_name).is_err() {
|
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
if assert_bounds(source, emacs, rust).is_err() {
|
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(DiffResult {
|
|
|
|
status: this_status,
|
|
|
|
name: emacs_name.to_owned(),
|
|
|
|
message: None,
|
|
|
|
children: child_status,
|
|
|
|
})
|
|
|
|
}
|
2023-04-22 17:58:16 -04:00
|
|
|
|
|
|
|
fn compare_plain_text<'s>(
|
|
|
|
_source: &'s str,
|
|
|
|
emacs: &'s Token<'s>,
|
|
|
|
rust: &'s PlainText<'s>,
|
|
|
|
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
|
|
|
let mut this_status = DiffStatus::Good;
|
|
|
|
let mut message = None;
|
|
|
|
let text = emacs.as_text()?;
|
2023-04-24 18:21:38 -04:00
|
|
|
let emacs_text_length = {
|
|
|
|
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()?;
|
|
|
|
end_ind - start_ind
|
|
|
|
};
|
|
|
|
if rust.source.len() != emacs_text_length {
|
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
message = Some(format!(
|
|
|
|
"(emacs len != rust len) {:?} != {:?}",
|
|
|
|
emacs_text_length, rust.source.len()
|
|
|
|
));
|
|
|
|
}
|
2023-04-22 18:18:13 -04:00
|
|
|
let unquoted_text = text.unquote()?;
|
|
|
|
if unquoted_text != rust.source {
|
2023-04-22 17:58:16 -04:00
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
message = Some(format!(
|
|
|
|
"(emacs != rust) {:?} != {:?}",
|
2023-04-22 18:18:13 -04:00
|
|
|
unquoted_text, rust.source
|
2023-04-22 17:58:16 -04:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(DiffResult {
|
|
|
|
status: this_status,
|
|
|
|
name: "plain-text".to_owned(),
|
|
|
|
message,
|
|
|
|
children: Vec::new(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-04-22 20:22:07 -04:00
|
|
|
fn compare_bold<'s>(
|
2023-04-22 20:48:01 -04:00
|
|
|
source: &'s str,
|
2023-04-22 17:58:16 -04:00
|
|
|
emacs: &'s Token<'s>,
|
2023-04-22 20:22:07 -04:00
|
|
|
rust: &'s Bold<'s>,
|
2023-04-22 17:58:16 -04:00
|
|
|
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
2023-04-22 20:48:01 -04:00
|
|
|
let mut this_status = DiffStatus::Good;
|
|
|
|
let emacs_name = "bold";
|
|
|
|
if assert_name(emacs, emacs_name).is_err() {
|
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
if assert_bounds(source, emacs, rust).is_err() {
|
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
}
|
|
|
|
|
2023-04-22 17:58:16 -04:00
|
|
|
Ok(DiffResult {
|
2023-04-22 20:48:01 -04:00
|
|
|
status: this_status,
|
|
|
|
name: emacs_name.to_owned(),
|
2023-04-22 20:22:07 -04:00
|
|
|
message: None,
|
|
|
|
children: Vec::new(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
fn compare_italic<'s>(
|
2023-04-22 20:48:01 -04:00
|
|
|
source: &'s str,
|
2023-04-22 20:22:07 -04:00
|
|
|
emacs: &'s Token<'s>,
|
|
|
|
rust: &'s Italic<'s>,
|
|
|
|
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
2023-04-22 20:48:01 -04:00
|
|
|
let mut this_status = DiffStatus::Good;
|
|
|
|
let emacs_name = "italic";
|
|
|
|
if assert_name(emacs, emacs_name).is_err() {
|
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
if assert_bounds(source, emacs, rust).is_err() {
|
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
}
|
|
|
|
|
2023-04-22 20:22:07 -04:00
|
|
|
Ok(DiffResult {
|
2023-04-22 20:48:01 -04:00
|
|
|
status: this_status,
|
|
|
|
name: emacs_name.to_owned(),
|
2023-04-22 20:22:07 -04:00
|
|
|
message: None,
|
|
|
|
children: Vec::new(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
fn compare_underline<'s>(
|
2023-04-22 20:48:01 -04:00
|
|
|
source: &'s str,
|
2023-04-22 20:22:07 -04:00
|
|
|
emacs: &'s Token<'s>,
|
|
|
|
rust: &'s Underline<'s>,
|
|
|
|
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
2023-04-22 20:48:01 -04:00
|
|
|
let mut this_status = DiffStatus::Good;
|
|
|
|
let emacs_name = "underline";
|
|
|
|
if assert_name(emacs, emacs_name).is_err() {
|
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
if assert_bounds(source, emacs, rust).is_err() {
|
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
}
|
|
|
|
|
2023-04-22 20:22:07 -04:00
|
|
|
Ok(DiffResult {
|
2023-04-22 20:48:01 -04:00
|
|
|
status: this_status,
|
|
|
|
name: emacs_name.to_owned(),
|
2023-04-22 20:22:07 -04:00
|
|
|
message: None,
|
|
|
|
children: Vec::new(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
fn compare_verbatim<'s>(
|
2023-04-22 20:48:01 -04:00
|
|
|
source: &'s str,
|
2023-04-22 20:22:07 -04:00
|
|
|
emacs: &'s Token<'s>,
|
|
|
|
rust: &'s Verbatim<'s>,
|
|
|
|
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
2023-04-22 20:48:01 -04:00
|
|
|
let mut this_status = DiffStatus::Good;
|
|
|
|
let emacs_name = "verbatim";
|
|
|
|
if assert_name(emacs, emacs_name).is_err() {
|
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
if assert_bounds(source, emacs, rust).is_err() {
|
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
}
|
|
|
|
|
2023-04-22 20:22:07 -04:00
|
|
|
Ok(DiffResult {
|
2023-04-22 20:48:01 -04:00
|
|
|
status: this_status,
|
|
|
|
name: emacs_name.to_owned(),
|
2023-04-22 20:22:07 -04:00
|
|
|
message: None,
|
|
|
|
children: Vec::new(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
fn compare_code<'s>(
|
2023-04-22 20:48:01 -04:00
|
|
|
source: &'s str,
|
2023-04-22 20:22:07 -04:00
|
|
|
emacs: &'s Token<'s>,
|
|
|
|
rust: &'s Code<'s>,
|
|
|
|
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
2023-04-22 20:48:01 -04:00
|
|
|
let mut this_status = DiffStatus::Good;
|
|
|
|
let emacs_name = "code";
|
|
|
|
if assert_name(emacs, emacs_name).is_err() {
|
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
if assert_bounds(source, emacs, rust).is_err() {
|
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
}
|
|
|
|
|
2023-04-22 20:22:07 -04:00
|
|
|
Ok(DiffResult {
|
2023-04-22 20:48:01 -04:00
|
|
|
status: this_status,
|
|
|
|
name: emacs_name.to_owned(),
|
2023-04-22 20:22:07 -04:00
|
|
|
message: None,
|
|
|
|
children: Vec::new(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
fn compare_strike_through<'s>(
|
2023-04-22 20:48:01 -04:00
|
|
|
source: &'s str,
|
2023-04-22 20:22:07 -04:00
|
|
|
emacs: &'s Token<'s>,
|
|
|
|
rust: &'s StrikeThrough<'s>,
|
|
|
|
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
2023-04-22 20:48:01 -04:00
|
|
|
let mut this_status = DiffStatus::Good;
|
|
|
|
let emacs_name = "strike-through";
|
|
|
|
if assert_name(emacs, emacs_name).is_err() {
|
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
if assert_bounds(source, emacs, rust).is_err() {
|
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
}
|
|
|
|
|
2023-04-22 20:22:07 -04:00
|
|
|
Ok(DiffResult {
|
2023-04-22 20:48:01 -04:00
|
|
|
status: this_status,
|
|
|
|
name: emacs_name.to_owned(),
|
2023-04-22 17:58:16 -04:00
|
|
|
message: None,
|
|
|
|
children: Vec::new(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
fn compare_regular_link<'s>(
|
2023-04-23 16:17:52 -04:00
|
|
|
source: &'s str,
|
|
|
|
emacs: &'s Token<'s>,
|
|
|
|
rust: &'s RegularLink<'s>,
|
2023-04-22 17:58:16 -04:00
|
|
|
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
2023-04-23 16:17:52 -04:00
|
|
|
let mut this_status = DiffStatus::Good;
|
|
|
|
let emacs_name = "link";
|
|
|
|
if assert_name(emacs, emacs_name).is_err() {
|
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
if assert_bounds(source, emacs, rust).is_err() {
|
|
|
|
this_status = DiffStatus::Bad;
|
|
|
|
}
|
|
|
|
|
2023-04-22 17:58:16 -04:00
|
|
|
Ok(DiffResult {
|
2023-04-23 16:17:52 -04:00
|
|
|
status: this_status,
|
|
|
|
name: emacs_name.to_owned(),
|
2023-04-22 17:58:16 -04:00
|
|
|
message: None,
|
|
|
|
children: Vec::new(),
|
|
|
|
})
|
|
|
|
}
|