First stab at implementing comments.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
use super::sexp::Token;
|
||||
use crate::compare::util::get_offsets;
|
||||
use crate::parser::Comment;
|
||||
use crate::parser::Document;
|
||||
use crate::parser::DocumentElement;
|
||||
use crate::parser::Element;
|
||||
@@ -216,7 +217,7 @@ fn compare_element<'s>(
|
||||
Element::PlainList(obj) => compare_plain_list(source, emacs, obj),
|
||||
Element::GreaterBlock(obj) => compare_greater_block(source, emacs, obj),
|
||||
Element::FootnoteDefinition(obj) => compare_footnote_definition(source, emacs, obj),
|
||||
Element::Comment(obj) => todo!(),
|
||||
Element::Comment(obj) => compare_comment(source, emacs, obj),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -454,3 +455,44 @@ fn compare_footnote_definition<'s>(
|
||||
children: child_status,
|
||||
})
|
||||
}
|
||||
|
||||
fn compare_comment<'s>(
|
||||
source: &'s str,
|
||||
emacs: &'s Token<'s>,
|
||||
rust: &'s Comment<'s>,
|
||||
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
||||
let children = emacs.as_list()?;
|
||||
let first_child = children
|
||||
.first()
|
||||
.ok_or("Should have at least one child.")?
|
||||
.as_atom()?;
|
||||
if first_child != "comment" {
|
||||
return Err("Comment should correspond to a comment cell.".into());
|
||||
}
|
||||
let mut child_status = Vec::new();
|
||||
let mut this_status = DiffStatus::Good;
|
||||
|
||||
let attributes_child = children
|
||||
.iter()
|
||||
.nth(1)
|
||||
.ok_or("Should have an attributes child.")?;
|
||||
let attributes_map = attributes_child.as_map()?;
|
||||
let begin = attributes_map
|
||||
.get(":begin")
|
||||
.ok_or("Missing :begin attribute.")?
|
||||
.as_atom()?;
|
||||
let end = attributes_map
|
||||
.get(":end")
|
||||
.ok_or("Missing :end attribute.")?
|
||||
.as_atom()?;
|
||||
let (rust_begin, rust_end) = get_offsets(source, rust);
|
||||
if (rust_begin + 1).to_string() != begin || (rust_end + 1).to_string() != end {
|
||||
this_status = DiffStatus::Bad;
|
||||
}
|
||||
|
||||
Ok(DiffResult {
|
||||
status: this_status,
|
||||
name: "comment".to_owned(),
|
||||
children: child_status,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user