Simplify wasm diff result types.
This commit is contained in:
parent
20a7c89084
commit
1faaeeebf1
@ -9,25 +9,15 @@ pub fn wasm_compare_document<'b, 's, 'p>(
|
||||
source: &'s str,
|
||||
emacs: &'b Token<'s>,
|
||||
wasm: WasmDocument<'s, 'p>,
|
||||
) -> Result<WasmDiffEntry<'b, 's>, Box<dyn std::error::Error>> {
|
||||
) -> Result<WasmDiffResult<'s>, Box<dyn std::error::Error>> {
|
||||
wasm.compare_ast_node(source, emacs)
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum WasmDiffEntry<'b, 's> {
|
||||
WasmDiffResult(WasmDiffResult<'b, 's>),
|
||||
WasmDiffLayer(WasmDiffLayer<'b, 's>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct WasmDiffResult<'b, 's> {
|
||||
status: WasmDiffStatus,
|
||||
pub struct WasmDiffResult<'s> {
|
||||
status: Vec<WasmDiffStatus>,
|
||||
name: Cow<'s, str>,
|
||||
message: Option<String>,
|
||||
children: Vec<WasmDiffEntry<'b, 's>>,
|
||||
rust_source: &'s str,
|
||||
#[allow(dead_code)]
|
||||
emacs_token: &'b Token<'s>,
|
||||
children: Vec<WasmDiffResult<'s>>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@ -36,51 +26,26 @@ pub(crate) enum WasmDiffStatus {
|
||||
Bad(Cow<'static, str>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct WasmDiffLayer<'b, 's> {
|
||||
name: Cow<'s, str>,
|
||||
children: Vec<WasmDiffEntry<'b, 's>>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct WasmDiffList<'b, 's> {
|
||||
status: WasmDiffStatus,
|
||||
children: Vec<WasmDiffEntry<'b, 's>>,
|
||||
}
|
||||
|
||||
impl<'b, 's> WasmDiffList<'b, 's> {
|
||||
fn apply(
|
||||
&self,
|
||||
status: &mut WasmDiffStatus,
|
||||
children: &mut Vec<WasmDiffEntry<'b, 's>>,
|
||||
) -> Result<WasmDiffEntry<'b, 's>, Box<dyn std::error::Error>> {
|
||||
todo!()
|
||||
}
|
||||
impl<'s> WasmDiffResult<'s> {
|
||||
// fn apply(
|
||||
// &self,
|
||||
// status: &mut WasmDiffStatus,
|
||||
// children: &mut Vec<WasmDiffEntry<'s>>,
|
||||
// ) -> Result<WasmDiffEntry<'s>, Box<dyn std::error::Error>> {
|
||||
// todo!()
|
||||
// }
|
||||
|
||||
fn extend(
|
||||
&self,
|
||||
other: &mut WasmDiffList<'b, 's>,
|
||||
) -> Result<WasmDiffEntry<'b, 's>, Box<dyn std::error::Error>> {
|
||||
todo!()
|
||||
&mut self,
|
||||
other: WasmDiffResult<'s>,
|
||||
) -> Result<&mut WasmDiffResult<'s>, Box<dyn std::error::Error>> {
|
||||
if self.name.is_empty() {
|
||||
self.name = other.name;
|
||||
}
|
||||
self.status.extend(other.status);
|
||||
self.children.extend(other.children);
|
||||
Ok(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'b, 's> WasmDiffEntry<'b, 's> {
|
||||
// fn has_bad_children(&self) -> bool {
|
||||
// match self {
|
||||
// DiffEntry::DiffResult(diff) => &diff.children,
|
||||
// DiffEntry::DiffLayer(diff) => &diff.children,
|
||||
// }
|
||||
// .iter()
|
||||
// .any(|child| child.is_immediately_bad() || child.has_bad_children())
|
||||
// }
|
||||
|
||||
// fn is_immediately_bad(&self) -> bool {
|
||||
// match self {
|
||||
// DiffEntry::DiffResult(diff) => matches!(diff.status, DiffStatus::Bad),
|
||||
// DiffEntry::DiffLayer(_) => false,
|
||||
// }
|
||||
// }
|
||||
|
||||
pub fn is_bad(&self) -> bool {
|
||||
todo!()
|
||||
@ -88,48 +53,88 @@ impl<'b, 's> WasmDiffEntry<'b, 's> {
|
||||
}
|
||||
|
||||
pub fn print(&self, original_document: &str) -> Result<(), Box<dyn std::error::Error>> {
|
||||
self.print_indented(0, original_document)
|
||||
}
|
||||
|
||||
fn print_indented(
|
||||
&self,
|
||||
indentation: usize,
|
||||
original_document: &str,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
// self.print_indented(0, original_document)
|
||||
todo!()
|
||||
// match self {
|
||||
// WasmDiffEntry::WasmDiffResult(diff) => {
|
||||
// diff.print_indented(indentation, original_document)
|
||||
// }
|
||||
// WasmDiffEntry::WasmDiffLayer(diff) => {
|
||||
// diff.print_indented(indentation, original_document)
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
fn wasm_compare_list<'b, 's, 'p, EI, WI, WC>(
|
||||
impl<'s> Default for WasmDiffResult<'s> {
|
||||
fn default() -> Self {
|
||||
WasmDiffResult {
|
||||
status: Vec::new(),
|
||||
name: "".into(),
|
||||
children: Vec::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// impl<'s> WasmDiffEntry<'s> {
|
||||
// // fn has_bad_children(&self) -> bool {
|
||||
// // match self {
|
||||
// // DiffEntry::DiffResult(diff) => &diff.children,
|
||||
// // DiffEntry::DiffLayer(diff) => &diff.children,
|
||||
// // }
|
||||
// // .iter()
|
||||
// // .any(|child| child.is_immediately_bad() || child.has_bad_children())
|
||||
// // }
|
||||
|
||||
// // fn is_immediately_bad(&self) -> bool {
|
||||
// // match self {
|
||||
// // DiffEntry::DiffResult(diff) => matches!(diff.status, DiffStatus::Bad),
|
||||
// // DiffEntry::DiffLayer(_) => false,
|
||||
// // }
|
||||
// // }
|
||||
|
||||
// pub fn is_bad(&self) -> bool {
|
||||
// todo!()
|
||||
// // self.is_immediately_bad() || self.has_bad_children()
|
||||
// }
|
||||
|
||||
// pub fn print(&self, original_document: &str) -> Result<(), Box<dyn std::error::Error>> {
|
||||
// self.print_indented(0, original_document)
|
||||
// }
|
||||
|
||||
// fn print_indented(
|
||||
// &self,
|
||||
// indentation: usize,
|
||||
// original_document: &str,
|
||||
// ) -> Result<(), Box<dyn std::error::Error>> {
|
||||
// todo!()
|
||||
// // match self {
|
||||
// // WasmDiffEntry::WasmDiffResult(diff) => {
|
||||
// // diff.print_indented(indentation, original_document)
|
||||
// // }
|
||||
// // WasmDiffEntry::WasmDiffLayer(diff) => {
|
||||
// // diff.print_indented(indentation, original_document)
|
||||
// // }
|
||||
// // }
|
||||
// }
|
||||
// }
|
||||
|
||||
fn wasm_compare_list<'b, 's: 'b, 'p, EI, WI, WC>(
|
||||
source: &'s str,
|
||||
emacs: EI,
|
||||
wasm: WI,
|
||||
) -> Result<WasmDiffList<'b, 's>, Box<dyn std::error::Error>>
|
||||
) -> Result<WasmDiffResult<'s>, Box<dyn std::error::Error>>
|
||||
where
|
||||
EI: Iterator<Item = &'b Token<'s>> + ExactSizeIterator,
|
||||
WI: Iterator<Item = WC> + ExactSizeIterator,
|
||||
WC: WasmElispCompare<'s, 'p>,
|
||||
{
|
||||
let status = Vec::new();
|
||||
let emacs_length = emacs.len();
|
||||
let wasm_length = wasm.len();
|
||||
if emacs_length != wasm_length {
|
||||
return Ok(WasmDiffList {
|
||||
status: WasmDiffStatus::Bad(
|
||||
return Ok(WasmDiffResult {
|
||||
status: vec![WasmDiffStatus::Bad(
|
||||
format!(
|
||||
"Child length mismatch (emacs != rust) {:?} != {:?}",
|
||||
emacs_length, wasm_length
|
||||
)
|
||||
.into(),
|
||||
),
|
||||
)],
|
||||
children: Vec::new(),
|
||||
name: "".into(),
|
||||
});
|
||||
}
|
||||
|
||||
@ -137,9 +142,10 @@ where
|
||||
for (emacs_child, wasm_child) in emacs.zip(wasm) {
|
||||
child_status.push(wasm_child.compare_ast_node(source, emacs_child)?);
|
||||
}
|
||||
Ok(WasmDiffList {
|
||||
status: WasmDiffStatus::Good,
|
||||
Ok(WasmDiffResult {
|
||||
status,
|
||||
children: child_status,
|
||||
name: "".into(),
|
||||
})
|
||||
}
|
||||
|
||||
@ -148,7 +154,7 @@ impl<'s, 'p, WAN: WasmElispCompare<'s, 'p>> WasmElispCompare<'s, 'p> for &WAN {
|
||||
&self,
|
||||
source: &'s str,
|
||||
emacs: &'b Token<'s>,
|
||||
) -> Result<WasmDiffEntry<'b, 's>, Box<dyn std::error::Error>> {
|
||||
) -> Result<WasmDiffResult<'s>, Box<dyn std::error::Error>> {
|
||||
(*self).compare_ast_node(source, emacs)
|
||||
}
|
||||
}
|
||||
@ -158,7 +164,7 @@ impl<'s, 'p> WasmElispCompare<'s, 'p> for WasmAstNode<'s, 'p> {
|
||||
&self,
|
||||
source: &'s str,
|
||||
emacs: &'b Token<'s>,
|
||||
) -> Result<WasmDiffEntry<'b, 's>, Box<dyn std::error::Error>> {
|
||||
) -> Result<WasmDiffResult<'s>, Box<dyn std::error::Error>> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
@ -168,10 +174,11 @@ impl<'s, 'p> WasmElispCompare<'s, 'p> for WasmDocument<'s, 'p> {
|
||||
&self,
|
||||
source: &'s str,
|
||||
emacs: &'b Token<'s>,
|
||||
) -> Result<WasmDiffEntry<'b, 's>, Box<dyn std::error::Error>> {
|
||||
) -> Result<WasmDiffResult<'s>, Box<dyn std::error::Error>> {
|
||||
let mut result = WasmDiffResult::default();
|
||||
let emacs_children = emacs.as_list()?.iter().skip(2);
|
||||
let wasm_children = self.children.iter();
|
||||
let child_status = wasm_compare_list(source, emacs_children, wasm_children)?;
|
||||
result.extend(wasm_compare_list(source, emacs_children, wasm_children)?)?;
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
use super::compare::WasmDiffEntry;
|
||||
use super::compare::WasmDiffResult;
|
||||
use crate::compare::Token;
|
||||
|
||||
pub trait WasmElispCompare<'s, 'p> {
|
||||
@ -6,5 +6,5 @@ pub trait WasmElispCompare<'s, 'p> {
|
||||
&self,
|
||||
source: &'s str,
|
||||
emacs: &'b Token<'s>,
|
||||
) -> Result<WasmDiffEntry<'b, 's>, Box<dyn std::error::Error>>;
|
||||
) -> Result<WasmDiffResult<'s>, Box<dyn std::error::Error>>;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user