Improving WasmElispCompare.
This commit is contained in:
parent
e83417b243
commit
20a7c89084
@ -15,7 +15,7 @@ use crate::wasm::to_wasm::ToWasmStandardProperties;
|
|||||||
pub struct WasmDocument<'s, 'p> {
|
pub struct WasmDocument<'s, 'p> {
|
||||||
standard_properties: WasmStandardProperties,
|
standard_properties: WasmStandardProperties,
|
||||||
additional_properties: Vec<(String, &'s str)>,
|
additional_properties: Vec<(String, &'s str)>,
|
||||||
children: Vec<WasmAstNode<'s, 'p>>,
|
pub(crate) children: Vec<WasmAstNode<'s, 'p>>,
|
||||||
category: Option<&'p str>,
|
category: Option<&'p str>,
|
||||||
path: Option<PathBuf>,
|
path: Option<PathBuf>,
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ pub struct WasmDiffResult<'b, 's> {
|
|||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(crate) enum WasmDiffStatus {
|
pub(crate) enum WasmDiffStatus {
|
||||||
Good,
|
Good,
|
||||||
Bad,
|
Bad(Cow<'static, str>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -42,6 +42,29 @@ pub struct WasmDiffLayer<'b, 's> {
|
|||||||
children: Vec<WasmDiffEntry<'b, 's>>,
|
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!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn extend(
|
||||||
|
&self,
|
||||||
|
other: &mut WasmDiffList<'b, 's>,
|
||||||
|
) -> Result<WasmDiffEntry<'b, 's>, Box<dyn std::error::Error>> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'b, 's> WasmDiffEntry<'b, 's> {
|
impl<'b, 's> WasmDiffEntry<'b, 's> {
|
||||||
// fn has_bad_children(&self) -> bool {
|
// fn has_bad_children(&self) -> bool {
|
||||||
// match self {
|
// match self {
|
||||||
@ -85,92 +108,52 @@ impl<'b, 's> WasmDiffEntry<'b, 's> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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!(),
|
|
||||||
}
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn wasm_compare_list<'b, 's, 'p, EI, WI, WC>(
|
fn wasm_compare_list<'b, 's, 'p, EI, WI, WC>(
|
||||||
source: &'s str,
|
source: &'s str,
|
||||||
emacs: EI,
|
emacs: EI,
|
||||||
wasm: WI,
|
wasm: WI,
|
||||||
) -> Result<WasmDiffEntry<'b, 's>, Box<dyn std::error::Error>>
|
) -> Result<WasmDiffList<'b, 's>, Box<dyn std::error::Error>>
|
||||||
where
|
where
|
||||||
EI: Iterator<Item = &'b Token<'s>> + ExactSizeIterator,
|
EI: Iterator<Item = &'b Token<'s>> + ExactSizeIterator,
|
||||||
WI: Iterator<Item = WC> + ExactSizeIterator,
|
WI: Iterator<Item = WC> + ExactSizeIterator,
|
||||||
WC: WasmElispCompare<'s, 'p>,
|
WC: WasmElispCompare<'s, 'p>,
|
||||||
{
|
{
|
||||||
// let mut this_status = WasmDiffStatus::Good;
|
let emacs_length = emacs.len();
|
||||||
// let mut child_status = Vec::new();
|
let wasm_length = wasm.len();
|
||||||
// let mut message = None;
|
if emacs_length != wasm_length {
|
||||||
|
return Ok(WasmDiffList {
|
||||||
|
status: WasmDiffStatus::Bad(
|
||||||
|
format!(
|
||||||
|
"Child length mismatch (emacs != rust) {:?} != {:?}",
|
||||||
|
emacs_length, wasm_length
|
||||||
|
)
|
||||||
|
.into(),
|
||||||
|
),
|
||||||
|
children: Vec::new(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
todo!()
|
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(WasmDiffList {
|
||||||
|
status: WasmDiffStatus::Good,
|
||||||
|
children: child_status,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'s, 'p> WasmElispCompare<'s, 'p> for WasmDocument<'s, 'p> {
|
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>,
|
||||||
|
) -> Result<WasmDiffEntry<'b, '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>(
|
fn compare_ast_node<'b>(
|
||||||
&self,
|
&self,
|
||||||
source: &'s str,
|
source: &'s str,
|
||||||
@ -179,3 +162,16 @@ impl<'s, 'p> WasmElispCompare<'s, 'p> for WasmDocument<'s, 'p> {
|
|||||||
todo!()
|
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<WasmDiffEntry<'b, 's>, Box<dyn std::error::Error>> {
|
||||||
|
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)?;
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -3,7 +3,7 @@ use crate::compare::Token;
|
|||||||
|
|
||||||
pub trait WasmElispCompare<'s, 'p> {
|
pub trait WasmElispCompare<'s, 'p> {
|
||||||
fn compare_ast_node<'b>(
|
fn compare_ast_node<'b>(
|
||||||
&'p self,
|
&self,
|
||||||
source: &'s str,
|
source: &'s str,
|
||||||
emacs: &'b Token<'s>,
|
emacs: &'b Token<'s>,
|
||||||
) -> Result<WasmDiffEntry<'b, 's>, Box<dyn std::error::Error>>;
|
) -> Result<WasmDiffEntry<'b, 's>, Box<dyn std::error::Error>>;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user