Compare commits
3 Commits
36b80dc093
...
1faaeeebf1
Author | SHA1 | Date | |
---|---|---|---|
![]() |
1faaeeebf1 | ||
![]() |
20a7c89084 | ||
![]() |
e83417b243 |
@ -15,7 +15,7 @@ use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
pub struct WasmDocument<'s, 'p> {
|
||||
standard_properties: WasmStandardProperties,
|
||||
additional_properties: Vec<(String, &'s str)>,
|
||||
children: Vec<WasmAstNode<'s, 'p>>,
|
||||
pub(crate) children: Vec<WasmAstNode<'s, 'p>>,
|
||||
category: Option<&'p str>,
|
||||
path: Option<PathBuf>,
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
use std::borrow::Cow;
|
||||
|
||||
use super::elisp_compare::WasmElispCompare;
|
||||
use crate::compare::Token;
|
||||
use crate::wasm::WasmAstNode;
|
||||
use crate::wasm::WasmDocument;
|
||||
@ -8,56 +9,43 @@ 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>> {
|
||||
// wasm_compare_ast_node(
|
||||
todo!()
|
||||
) -> 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)]
|
||||
pub(crate) enum WasmDiffStatus {
|
||||
Good,
|
||||
Bad,
|
||||
Bad(Cow<'static, str>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct WasmDiffLayer<'b, 's> {
|
||||
name: Cow<'s, str>,
|
||||
children: Vec<WasmDiffEntry<'b, 's>>,
|
||||
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(
|
||||
&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!()
|
||||
@ -65,121 +53,132 @@ 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>> {
|
||||
todo!()
|
||||
// match self {
|
||||
// WasmDiffEntry::WasmDiffResult(diff) => {
|
||||
// diff.print_indented(indentation, original_document)
|
||||
// }
|
||||
// WasmDiffEntry::WasmDiffLayer(diff) => {
|
||||
// diff.print_indented(indentation, original_document)
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
fn wasm_compare_ast_node<'b, 's, 'p>(
|
||||
source: &'s str,
|
||||
emacs: &'b Token<'s>,
|
||||
wasm: WasmAstNode<'s, 'p>,
|
||||
) -> Result<WasmDiffEntry<'b, 's>, Box<dyn std::error::Error>> {
|
||||
match wasm {
|
||||
WasmAstNode::Document(_) => todo!(),
|
||||
WasmAstNode::Headline(_) => todo!(),
|
||||
WasmAstNode::Section(_) => todo!(),
|
||||
WasmAstNode::Paragraph(_) => todo!(),
|
||||
WasmAstNode::PlainList(_) => todo!(),
|
||||
WasmAstNode::PlainListItem(_) => todo!(),
|
||||
WasmAstNode::CenterBlock(_) => todo!(),
|
||||
WasmAstNode::QuoteBlock(_) => todo!(),
|
||||
WasmAstNode::SpecialBlock(_) => todo!(),
|
||||
WasmAstNode::DynamicBlock(_) => todo!(),
|
||||
WasmAstNode::FootnoteDefinition(_) => todo!(),
|
||||
WasmAstNode::Comment(_) => todo!(),
|
||||
WasmAstNode::Drawer(_) => todo!(),
|
||||
WasmAstNode::PropertyDrawer(_) => todo!(),
|
||||
WasmAstNode::NodeProperty(_) => todo!(),
|
||||
WasmAstNode::Table(_) => todo!(),
|
||||
WasmAstNode::TableRow(_) => todo!(),
|
||||
WasmAstNode::VerseBlock(_) => todo!(),
|
||||
WasmAstNode::CommentBlock(_) => todo!(),
|
||||
WasmAstNode::ExampleBlock(_) => todo!(),
|
||||
WasmAstNode::ExportBlock(_) => todo!(),
|
||||
WasmAstNode::SrcBlock(_) => todo!(),
|
||||
WasmAstNode::Clock(_) => todo!(),
|
||||
WasmAstNode::DiarySexp(_) => todo!(),
|
||||
WasmAstNode::Planning(_) => todo!(),
|
||||
WasmAstNode::FixedWidthArea(_) => todo!(),
|
||||
WasmAstNode::HorizontalRule(_) => todo!(),
|
||||
WasmAstNode::Keyword(_) => todo!(),
|
||||
WasmAstNode::BabelCall(_) => todo!(),
|
||||
WasmAstNode::LatexEnvironment(_) => todo!(),
|
||||
WasmAstNode::Bold(_) => todo!(),
|
||||
WasmAstNode::Italic(_) => todo!(),
|
||||
WasmAstNode::Underline(_) => todo!(),
|
||||
WasmAstNode::StrikeThrough(_) => todo!(),
|
||||
WasmAstNode::Code(_) => todo!(),
|
||||
WasmAstNode::Verbatim(_) => todo!(),
|
||||
WasmAstNode::PlainText(_) => todo!(),
|
||||
WasmAstNode::RegularLink(_) => todo!(),
|
||||
WasmAstNode::RadioLink(_) => todo!(),
|
||||
WasmAstNode::RadioTarget(_) => todo!(),
|
||||
WasmAstNode::PlainLink(_) => todo!(),
|
||||
WasmAstNode::AngleLink(_) => todo!(),
|
||||
WasmAstNode::OrgMacro(_) => todo!(),
|
||||
WasmAstNode::Entity(_) => todo!(),
|
||||
WasmAstNode::LatexFragment(_) => todo!(),
|
||||
WasmAstNode::ExportSnippet(_) => todo!(),
|
||||
WasmAstNode::FootnoteReference(_) => todo!(),
|
||||
WasmAstNode::Citation(_) => todo!(),
|
||||
WasmAstNode::CitationReference(_) => todo!(),
|
||||
WasmAstNode::InlineBabelCall(_) => todo!(),
|
||||
WasmAstNode::InlineSourceBlock(_) => todo!(),
|
||||
WasmAstNode::LineBreak(_) => todo!(),
|
||||
WasmAstNode::Target(_) => todo!(),
|
||||
WasmAstNode::StatisticsCookie(_) => todo!(),
|
||||
WasmAstNode::Subscript(_) => todo!(),
|
||||
WasmAstNode::Superscript(_) => todo!(),
|
||||
WasmAstNode::TableCell(_) => todo!(),
|
||||
WasmAstNode::Timestamp(_) => todo!(),
|
||||
}
|
||||
// self.print_indented(0, original_document)
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
// fn wasm_compare_list<'b, 's, EI, WI, WC>(
|
||||
// source: &'s str,
|
||||
// emacs: EI,
|
||||
// wasm: WI,
|
||||
// // emacs: &'b Token<'s>,
|
||||
// // wasm: WasmDocument<'s>,
|
||||
// ) -> Result<WasmDiffEntry<'b, 's>, Box<dyn std::error::Error>>
|
||||
// where
|
||||
// EI: Iterator<Item = &'b Token<'s>> + ExactSizeIterator,
|
||||
// WI: Iterator<Item = WC>,
|
||||
// WasmAstNode<'b, 's>: From<WC>,
|
||||
// {
|
||||
// let mut this_status = WasmDiffStatus::Good;
|
||||
// let mut child_status = Vec::new();
|
||||
// let mut message = None;
|
||||
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()
|
||||
// }
|
||||
|
||||
fn impl_wasm_compare_document<'b, 's, 'p>(
|
||||
// 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<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(WasmDiffResult {
|
||||
status: vec![WasmDiffStatus::Bad(
|
||||
format!(
|
||||
"Child length mismatch (emacs != rust) {:?} != {:?}",
|
||||
emacs_length, wasm_length
|
||||
)
|
||||
.into(),
|
||||
)],
|
||||
children: Vec::new(),
|
||||
name: "".into(),
|
||||
});
|
||||
}
|
||||
|
||||
let mut child_status = Vec::with_capacity(emacs_length);
|
||||
for (emacs_child, wasm_child) in emacs.zip(wasm) {
|
||||
child_status.push(wasm_child.compare_ast_node(source, emacs_child)?);
|
||||
}
|
||||
Ok(WasmDiffResult {
|
||||
status,
|
||||
children: child_status,
|
||||
name: "".into(),
|
||||
})
|
||||
}
|
||||
|
||||
impl<'s, 'p, WAN: WasmElispCompare<'s, 'p>> WasmElispCompare<'s, 'p> for &WAN {
|
||||
fn compare_ast_node<'b>(
|
||||
&self,
|
||||
source: &'s str,
|
||||
emacs: &'b Token<'s>,
|
||||
wasm: WasmDocument<'s, 'p>,
|
||||
) -> Result<WasmDiffEntry<'b, 's>, Box<dyn std::error::Error>> {
|
||||
let mut this_status = WasmDiffStatus::Good;
|
||||
// let mut child_status = Vec::new();
|
||||
// let mut message = None;
|
||||
) -> Result<WasmDiffResult<'s>, Box<dyn std::error::Error>> {
|
||||
(*self).compare_ast_node(source, emacs)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'s, 'p> WasmElispCompare<'s, 'p> for WasmAstNode<'s, 'p> {
|
||||
fn compare_ast_node<'b>(
|
||||
&self,
|
||||
source: &'s str,
|
||||
emacs: &'b Token<'s>,
|
||||
) -> Result<WasmDiffResult<'s>, Box<dyn std::error::Error>> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'s, 'p> WasmElispCompare<'s, 'p> for WasmDocument<'s, 'p> {
|
||||
fn compare_ast_node<'b>(
|
||||
&self,
|
||||
source: &'s str,
|
||||
emacs: &'b Token<'s>,
|
||||
) -> 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();
|
||||
result.extend(wasm_compare_list(source, emacs_children, wasm_children)?)?;
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
10
src/wasm_test/elisp_compare.rs
Normal file
10
src/wasm_test/elisp_compare.rs
Normal file
@ -0,0 +1,10 @@
|
||||
use super::compare::WasmDiffResult;
|
||||
use crate::compare::Token;
|
||||
|
||||
pub trait WasmElispCompare<'s, 'p> {
|
||||
fn compare_ast_node<'b>(
|
||||
&self,
|
||||
source: &'s str,
|
||||
emacs: &'b Token<'s>,
|
||||
) -> Result<WasmDiffResult<'s>, Box<dyn std::error::Error>>;
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
mod compare;
|
||||
mod elisp_compare;
|
||||
mod runner;
|
||||
|
||||
pub use runner::wasm_run_anonymous_compare;
|
||||
|
Loading…
x
Reference in New Issue
Block a user