Compare plain list bounds.
This commit is contained in:
parent
f27965001d
commit
75a47deedd
@ -2,10 +2,11 @@ use super::sexp::Token;
|
|||||||
use crate::compare::util::get_offsets;
|
use crate::compare::util::get_offsets;
|
||||||
use crate::parser::Document;
|
use crate::parser::Document;
|
||||||
use crate::parser::DocumentElement;
|
use crate::parser::DocumentElement;
|
||||||
use crate::parser::Heading;
|
|
||||||
use crate::parser::Section;
|
|
||||||
use crate::parser::Paragraph;
|
|
||||||
use crate::parser::Element;
|
use crate::parser::Element;
|
||||||
|
use crate::parser::Heading;
|
||||||
|
use crate::parser::Paragraph;
|
||||||
|
use crate::parser::PlainList;
|
||||||
|
use crate::parser::Section;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct DiffResult {
|
pub struct DiffResult {
|
||||||
@ -102,7 +103,7 @@ pub fn compare_document<'s>(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn compare_section<'s>(
|
fn compare_section<'s>(
|
||||||
source: &'s str,
|
source: &'s str,
|
||||||
emacs: &'s Token<'s>,
|
emacs: &'s Token<'s>,
|
||||||
rust: &'s Section<'s>,
|
rust: &'s Section<'s>,
|
||||||
@ -145,7 +146,7 @@ pub fn compare_section<'s>(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn compare_heading<'s>(
|
fn compare_heading<'s>(
|
||||||
source: &'s str,
|
source: &'s str,
|
||||||
emacs: &'s Token<'s>,
|
emacs: &'s Token<'s>,
|
||||||
rust: &'s Heading<'s>,
|
rust: &'s Heading<'s>,
|
||||||
@ -181,10 +182,10 @@ pub fn compare_heading<'s>(
|
|||||||
match rust_child {
|
match rust_child {
|
||||||
DocumentElement::Heading(rust_heading) => {
|
DocumentElement::Heading(rust_heading) => {
|
||||||
child_status.push(compare_heading(source, emacs_child, rust_heading)?);
|
child_status.push(compare_heading(source, emacs_child, rust_heading)?);
|
||||||
},
|
}
|
||||||
DocumentElement::Section(rust_section) => {
|
DocumentElement::Section(rust_section) => {
|
||||||
child_status.push(compare_section(source, emacs_child, rust_section)?);
|
child_status.push(compare_section(source, emacs_child, rust_section)?);
|
||||||
},
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -195,26 +196,29 @@ pub fn compare_heading<'s>(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn compare_element<'s>(
|
fn compare_element<'s>(
|
||||||
source: &'s str,
|
source: &'s str,
|
||||||
emacs: &'s Token<'s>,
|
emacs: &'s Token<'s>,
|
||||||
rust: &'s Element<'s>,
|
rust: &'s Element<'s>,
|
||||||
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
||||||
match rust {
|
match rust {
|
||||||
Element::Paragraph(obj) => compare_paragraph(source, emacs, obj),
|
Element::Paragraph(obj) => compare_paragraph(source, emacs, obj),
|
||||||
Element::PlainList(_) => todo!(),
|
Element::PlainList(obj) => compare_plain_list(source, emacs, obj),
|
||||||
Element::GreaterBlock(_) => todo!(),
|
Element::GreaterBlock(_) => todo!(),
|
||||||
Element::FootnoteDefinition(_) => todo!(),
|
Element::FootnoteDefinition(_) => todo!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn compare_paragraph<'s>(
|
fn compare_paragraph<'s>(
|
||||||
source: &'s str,
|
source: &'s str,
|
||||||
emacs: &'s Token<'s>,
|
emacs: &'s Token<'s>,
|
||||||
rust: &'s Paragraph<'s>,
|
rust: &'s Paragraph<'s>,
|
||||||
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
||||||
let children = emacs.as_list()?;
|
let children = emacs.as_list()?;
|
||||||
let first_child = children.first().ok_or("Should have at least one child.")?.as_atom()?;
|
let first_child = children
|
||||||
|
.first()
|
||||||
|
.ok_or("Should have at least one child.")?
|
||||||
|
.as_atom()?;
|
||||||
if first_child != "paragraph" {
|
if first_child != "paragraph" {
|
||||||
return Err("Paragraph should correspond to a paragraph cell.".into());
|
return Err("Paragraph should correspond to a paragraph cell.".into());
|
||||||
}
|
}
|
||||||
@ -239,8 +243,7 @@ pub fn compare_paragraph<'s>(
|
|||||||
this_status = DiffStatus::Bad;
|
this_status = DiffStatus::Bad;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (emacs_child, rust_child) in children.iter().skip(2).zip(rust.children.iter()) {
|
for (emacs_child, rust_child) in children.iter().skip(2).zip(rust.children.iter()) {}
|
||||||
}
|
|
||||||
|
|
||||||
Ok(DiffResult {
|
Ok(DiffResult {
|
||||||
status: this_status,
|
status: this_status,
|
||||||
@ -248,3 +251,48 @@ pub fn compare_paragraph<'s>(
|
|||||||
children: child_status,
|
children: child_status,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 first_child = children
|
||||||
|
.first()
|
||||||
|
.ok_or("Should have at least one child.")?
|
||||||
|
.as_atom()?;
|
||||||
|
if first_child != "plain-list" {
|
||||||
|
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: "plain-list".to_owned(),
|
||||||
|
children: child_status,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
//plain-list
|
||||||
|
@ -20,6 +20,7 @@ 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 element::Element;
|
||||||
|
pub use greater_element::PlainList;
|
||||||
pub use lesser_element::Paragraph;
|
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