Compare table row and table cell bounds.

This commit is contained in:
Tom Alexander 2023-04-21 15:45:35 -04:00
parent 2703792644
commit 0fcfdd5ff2
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
3 changed files with 78 additions and 0 deletions

View File

@ -15,6 +15,8 @@ use crate::parser::PlainListItem;
use crate::parser::PropertyDrawer;
use crate::parser::Section;
use crate::parser::Table;
use crate::parser::TableCell;
use crate::parser::TableRow;
use crate::DynamicBlock;
#[derive(Debug)]
@ -479,6 +481,66 @@ fn compare_table<'s>(
this_status = DiffStatus::Bad;
}
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()?;
let mut child_status = Vec::new();
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;
}
for (emacs_child, rust_child) in children.iter().skip(2).zip(rust.children.iter()) {}
Ok(DiffResult {
status: this_status,
name: emacs_name.to_owned(),

View File

@ -10,8 +10,10 @@ use super::greater_element::GreaterBlock;
use super::greater_element::PlainList;
use super::greater_element::PropertyDrawer;
use super::greater_element::Table;
use super::greater_element::TableRow;
use super::lesser_element::Comment;
use super::lesser_element::Paragraph;
use super::lesser_element::TableCell;
use super::paragraph::paragraph;
use super::plain_list::plain_list;
use super::source::Source;
@ -113,6 +115,18 @@ impl<'s> Source<'s> for Table<'s> {
}
}
impl<'s> Source<'s> for TableRow<'s> {
fn get_source(&'s self) -> &'s str {
self.source
}
}
impl<'s> Source<'s> for TableCell<'s> {
fn get_source(&'s self) -> &'s str {
self.source
}
}
#[tracing::instrument(ret, level = "debug")]
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);

View File

@ -34,7 +34,9 @@ pub use greater_element::PlainList;
pub use greater_element::PlainListItem;
pub use greater_element::PropertyDrawer;
pub use greater_element::Table;
pub use greater_element::TableRow;
pub use lesser_element::Comment;
pub use lesser_element::Paragraph;
pub use lesser_element::TableCell;
pub use source::Source;
type Context<'r, 's> = &'r parser_context::ContextTree<'r, 's>;