Compare children of sections.
This commit is contained in:
parent
c4e6549feb
commit
2a601475fd
@ -4,6 +4,8 @@ use crate::parser::Document;
|
|||||||
use crate::parser::DocumentElement;
|
use crate::parser::DocumentElement;
|
||||||
use crate::parser::Heading;
|
use crate::parser::Heading;
|
||||||
use crate::parser::Section;
|
use crate::parser::Section;
|
||||||
|
use crate::parser::Paragraph;
|
||||||
|
use crate::parser::Element;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct DiffResult {
|
pub struct DiffResult {
|
||||||
@ -132,6 +134,10 @@ pub fn compare_section<'s>(
|
|||||||
this_status = DiffStatus::Bad;
|
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 {
|
Ok(DiffResult {
|
||||||
status: this_status,
|
status: this_status,
|
||||||
name: "section".to_owned(),
|
name: "section".to_owned(),
|
||||||
@ -188,3 +194,57 @@ pub fn compare_heading<'s>(
|
|||||||
children: child_status,
|
children: child_status,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub 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(_) => todo!(),
|
||||||
|
Element::GreaterBlock(_) => todo!(),
|
||||||
|
Element::FootnoteDefinition(_) => todo!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn compare_paragraph<'s>(
|
||||||
|
source: &'s str,
|
||||||
|
emacs: &'s Token<'s>,
|
||||||
|
rust: &'s Paragraph<'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 != "paragraph" {
|
||||||
|
return Err("Paragraph should correspond to a paragraph 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (emacs_child, rust_child) in children.iter().skip(2).zip(rust.children.iter()) {
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(DiffResult {
|
||||||
|
status: this_status,
|
||||||
|
name: "paragraph".to_owned(),
|
||||||
|
children: child_status,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
@ -32,6 +32,12 @@ impl<'s> Source<'s> for Element<'s> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'s> Source<'s> for Paragraph<'s> {
|
||||||
|
fn get_source(&'s self) -> &'s str {
|
||||||
|
self.source
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[tracing::instrument(ret, level = "debug")]
|
#[tracing::instrument(ret, level = "debug")]
|
||||||
pub fn element<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, Element<'s>> {
|
pub fn element<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, Element<'s>> {
|
||||||
let non_paragraph_matcher = parser_with_context!(non_paragraph_element)(context);
|
let non_paragraph_matcher = parser_with_context!(non_paragraph_element)(context);
|
||||||
|
@ -19,5 +19,7 @@ pub use document::Document;
|
|||||||
pub use document::DocumentElement;
|
pub use document::DocumentElement;
|
||||||
pub use document::Heading;
|
pub use document::Heading;
|
||||||
pub use document::Section;
|
pub use document::Section;
|
||||||
|
pub use element::Element;
|
||||||
|
pub use lesser_element::Paragraph;
|
||||||
pub use source::Source;
|
pub use source::Source;
|
||||||
type Context<'r, 's> = &'r parser_context::ContextTree<'r, 's>;
|
type Context<'r, 's> = &'r parser_context::ContextTree<'r, 's>;
|
||||||
|
Loading…
Reference in New Issue
Block a user