From c4e6549feb32f56d6f32b88cbf10c7fc836bb071 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Wed, 12 Apr 2023 11:35:02 -0400 Subject: [PATCH] Compare children of heading. --- src/compare/diff.rs | 27 ++++++++++++++++++--------- src/parser/mod.rs | 3 ++- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/compare/diff.rs b/src/compare/diff.rs index c4b15c8..3e69a6a 100644 --- a/src/compare/diff.rs +++ b/src/compare/diff.rs @@ -1,8 +1,9 @@ use super::sexp::Token; use crate::compare::util::get_offsets; use crate::parser::Document; -use crate::parser::Section; +use crate::parser::DocumentElement; use crate::parser::Heading; +use crate::parser::Section; #[derive(Debug)] pub struct DiffResult { @@ -31,16 +32,11 @@ impl DiffResult { } else { "GOOD" } - }, + } DiffStatus::Bad => "BAD", } }; - println!( - "{}{} {}", - " ".repeat(indentation), - status_text, - self.name - ); + println!("{}{} {}", " ".repeat(indentation), status_text, self.name); for child in self.children.iter() { child.print_indented(indentation + 1)?; } @@ -48,7 +44,9 @@ impl DiffResult { } pub fn has_bad_children(&self) -> bool { - self.children.iter().any(|child| {child.status == DiffStatus::Bad || child.has_bad_children()}) + self.children + .iter() + .any(|child| child.status == DiffStatus::Bad || child.has_bad_children()) } } @@ -173,6 +171,17 @@ pub fn compare_heading<'s>( this_status = DiffStatus::Bad; } + 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)?); + }, + DocumentElement::Section(rust_section) => { + child_status.push(compare_section(source, emacs_child, rust_section)?); + }, + }; + } + Ok(DiffResult { status: this_status, name: "heading".to_owned(), diff --git a/src/parser/mod.rs b/src/parser/mod.rs index 63bf5d8..9c810ce 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -16,7 +16,8 @@ mod source; mod util; pub use document::document; pub use document::Document; -pub use document::Section; +pub use document::DocumentElement; pub use document::Heading; +pub use document::Section; pub use source::Source; type Context<'r, 's> = &'r parser_context::ContextTree<'r, 's>;