Remove compare_element and compare_object.
This commit is contained in:
		
							parent
							
								
									418c5c1ce8
								
							
						
					
					
						commit
						52e0d305aa
					
				| @ -28,7 +28,6 @@ use crate::types::Document; | ||||
| use crate::types::DocumentElement; | ||||
| use crate::types::Drawer; | ||||
| use crate::types::DynamicBlock; | ||||
| use crate::types::Element; | ||||
| use crate::types::Entity; | ||||
| use crate::types::ExampleBlock; | ||||
| use crate::types::ExportBlock; | ||||
| @ -48,7 +47,6 @@ use crate::types::LatexEnvironment; | ||||
| use crate::types::LatexFragment; | ||||
| use crate::types::LineBreak; | ||||
| use crate::types::NodeProperty; | ||||
| use crate::types::Object; | ||||
| use crate::types::OrgMacro; | ||||
| use crate::types::Paragraph; | ||||
| use crate::types::PlainLink; | ||||
| @ -306,7 +304,7 @@ fn compare_ast_node<'b, 's>( | ||||
|     rust: AstNode<'b, 's>, | ||||
| ) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> { | ||||
|     let compare_result: Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> = match rust { | ||||
|         AstNode::Document(node) => compare_document(emacs, node), | ||||
|         AstNode::Document(node) => _compare_document(source, emacs, node), | ||||
|         AstNode::Heading(node) => compare_heading(source, emacs, node), | ||||
|         AstNode::Section(node) => compare_section(source, emacs, node), | ||||
|         AstNode::Paragraph(node) => compare_paragraph(source, emacs, node), | ||||
| @ -367,7 +365,7 @@ fn compare_ast_node<'b, 's>( | ||||
|     let mut compare_result = match compare_result.unwrap_or_else(|e| { | ||||
|         DiffResult { | ||||
|             status: DiffStatus::Bad, | ||||
|             name: "error!".into(), | ||||
|             name: rust.get_elisp_fact().get_elisp_name(), | ||||
|             message: Some(e.to_string()), | ||||
|             children: Vec::new(), | ||||
|             rust_source: rust.get_standard_properties().get_source(), | ||||
| @ -396,145 +394,22 @@ fn compare_ast_node<'b, 's>( | ||||
|     Ok(compare_result.into()) | ||||
| } | ||||
| 
 | ||||
| fn compare_element<'b, 's>( | ||||
|     source: &'s str, | ||||
|     emacs: &'b Token<'s>, | ||||
|     rust: &'b Element<'s>, | ||||
| ) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> { | ||||
|     let compare_result = match rust { | ||||
|         Element::Paragraph(obj) => compare_paragraph(source, emacs, obj), | ||||
|         Element::PlainList(obj) => compare_plain_list(source, emacs, obj), | ||||
|         Element::GreaterBlock(obj) => compare_greater_block(source, emacs, obj), | ||||
|         Element::DynamicBlock(obj) => compare_dynamic_block(source, emacs, obj), | ||||
|         Element::FootnoteDefinition(obj) => compare_footnote_definition(source, emacs, obj), | ||||
|         Element::Comment(obj) => compare_comment(source, emacs, obj), | ||||
|         Element::Drawer(obj) => compare_drawer(source, emacs, obj), | ||||
|         Element::PropertyDrawer(obj) => compare_property_drawer(source, emacs, obj), | ||||
|         Element::Table(obj) => compare_table(source, emacs, obj), | ||||
|         Element::VerseBlock(obj) => compare_verse_block(source, emacs, obj), | ||||
|         Element::CommentBlock(obj) => compare_comment_block(source, emacs, obj), | ||||
|         Element::ExampleBlock(obj) => compare_example_block(source, emacs, obj), | ||||
|         Element::ExportBlock(obj) => compare_export_block(source, emacs, obj), | ||||
|         Element::SrcBlock(obj) => compare_src_block(source, emacs, obj), | ||||
|         Element::Clock(obj) => compare_clock(source, emacs, obj), | ||||
|         Element::DiarySexp(obj) => compare_diary_sexp(source, emacs, obj), | ||||
|         Element::Planning(obj) => compare_planning(source, emacs, obj), | ||||
|         Element::FixedWidthArea(obj) => compare_fixed_width_area(source, emacs, obj), | ||||
|         Element::HorizontalRule(obj) => compare_horizontal_rule(source, emacs, obj), | ||||
|         Element::Keyword(obj) => compare_keyword(source, emacs, obj), | ||||
|         Element::BabelCall(obj) => compare_babel_call(source, emacs, obj), | ||||
|         Element::LatexEnvironment(obj) => compare_latex_environment(source, emacs, obj), | ||||
|     }; | ||||
| 
 | ||||
|     let mut compare_result = match compare_result.unwrap_or_else(|e| { | ||||
|         DiffResult { | ||||
|             status: DiffStatus::Bad, | ||||
|             name: "error!".into(), | ||||
|             message: Some(e.to_string()), | ||||
|             children: Vec::new(), | ||||
|             rust_source: rust.get_standard_properties().get_source(), | ||||
|             emacs_token: emacs, | ||||
|         } | ||||
|         .into() | ||||
|     }) { | ||||
|         DiffEntry::DiffResult(inner) => inner, | ||||
|         DiffEntry::DiffLayer(_) => { | ||||
|             unreachable!("Layers are only interior to DiffResults of AST nodes.") | ||||
|         } | ||||
|     }; | ||||
| 
 | ||||
|     match compare_standard_properties(source, emacs, rust) { | ||||
|         Err(err) => { | ||||
|             compare_result.status = DiffStatus::Bad; | ||||
|             compare_result.message = Some(err.to_string()) | ||||
|         } | ||||
|         Ok(_) => {} | ||||
|     } | ||||
| 
 | ||||
|     Ok(compare_result.into()) | ||||
| } | ||||
| 
 | ||||
| fn compare_object<'b, 's>( | ||||
|     source: &'s str, | ||||
|     emacs: &'b Token<'s>, | ||||
|     rust: &'b Object<'s>, | ||||
| ) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> { | ||||
|     let compare_result = match rust { | ||||
|         Object::Bold(obj) => compare_bold(source, emacs, obj), | ||||
|         Object::Italic(obj) => compare_italic(source, emacs, obj), | ||||
|         Object::Underline(obj) => compare_underline(source, emacs, obj), | ||||
|         Object::Verbatim(obj) => compare_verbatim(source, emacs, obj), | ||||
|         Object::Code(obj) => compare_code(source, emacs, obj), | ||||
|         Object::StrikeThrough(obj) => compare_strike_through(source, emacs, obj), | ||||
|         Object::PlainText(obj) => compare_plain_text(source, emacs, obj), | ||||
|         Object::RegularLink(obj) => compare_regular_link(source, emacs, obj), | ||||
|         Object::RadioLink(obj) => compare_radio_link(source, emacs, obj), | ||||
|         Object::RadioTarget(obj) => compare_radio_target(source, emacs, obj), | ||||
|         Object::PlainLink(obj) => compare_plain_link(source, emacs, obj), | ||||
|         Object::AngleLink(obj) => compare_angle_link(source, emacs, obj), | ||||
|         Object::OrgMacro(obj) => compare_org_macro(source, emacs, obj), | ||||
|         Object::Entity(obj) => compare_entity(source, emacs, obj), | ||||
|         Object::LatexFragment(obj) => compare_latex_fragment(source, emacs, obj), | ||||
|         Object::ExportSnippet(obj) => compare_export_snippet(source, emacs, obj), | ||||
|         Object::FootnoteReference(obj) => compare_footnote_reference(source, emacs, obj), | ||||
|         Object::Citation(obj) => compare_citation(source, emacs, obj), | ||||
|         Object::CitationReference(obj) => compare_citation_reference(source, emacs, obj), | ||||
|         Object::InlineBabelCall(obj) => compare_inline_babel_call(source, emacs, obj), | ||||
|         Object::InlineSourceBlock(obj) => compare_inline_source_block(source, emacs, obj), | ||||
|         Object::LineBreak(obj) => compare_line_break(source, emacs, obj), | ||||
|         Object::Target(obj) => compare_target(source, emacs, obj), | ||||
|         Object::StatisticsCookie(obj) => compare_statistics_cookie(source, emacs, obj), | ||||
|         Object::Subscript(obj) => compare_subscript(source, emacs, obj), | ||||
|         Object::Superscript(obj) => compare_superscript(source, emacs, obj), | ||||
|         Object::Timestamp(obj) => compare_timestamp(source, emacs, obj), | ||||
|     }; | ||||
|     let mut compare_result = match compare_result.unwrap_or_else(|e| { | ||||
|         DiffResult { | ||||
|             status: DiffStatus::Bad, | ||||
|             name: rust.get_elisp_fact().get_elisp_name(), | ||||
|             message: Some(e.to_string()), | ||||
|             children: Vec::new(), | ||||
|             rust_source: rust.get_standard_properties().get_source(), | ||||
|             emacs_token: emacs, | ||||
|         } | ||||
|         .into() | ||||
|     }) { | ||||
|         DiffEntry::DiffResult(inner) => inner, | ||||
|         DiffEntry::DiffLayer(_) => { | ||||
|             unreachable!("Layers are only interior to DiffResults of AST nodes.") | ||||
|         } | ||||
|     }; | ||||
| 
 | ||||
|     // PlainText is a special case because upstream Org-Mode uses relative values for the bounds in plaintext rather than absolute so the below checks do not account for that.
 | ||||
|     if let Object::PlainText(_) = rust { | ||||
|     } else { | ||||
|         match compare_standard_properties(source, emacs, rust) { | ||||
|             Err(err) => { | ||||
|                 compare_result.status = DiffStatus::Bad; | ||||
|                 compare_result.message = Some(err.to_string()) | ||||
|             } | ||||
|             Ok(_) => {} | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     Ok(compare_result.into()) | ||||
| } | ||||
| 
 | ||||
| pub fn compare_document<'b, 's>( | ||||
|     emacs: &'b Token<'s>, | ||||
|     rust: &'b Document<'s>, | ||||
| ) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> { | ||||
|     compare_ast_node(rust.source, emacs, rust.into()) | ||||
| } | ||||
| 
 | ||||
| fn _compare_document<'b, 's>( | ||||
|     source: &'s str, | ||||
|     emacs: &'b Token<'s>, | ||||
|     rust: &'b Document<'s>, | ||||
| ) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> { | ||||
|     let children = emacs.as_list()?; | ||||
|     let mut child_status = Vec::new(); | ||||
|     let mut this_status = DiffStatus::Good; | ||||
|     let mut message = None; | ||||
|     match compare_standard_properties(rust.source, emacs, rust) { | ||||
|         Err(err) => { | ||||
|             this_status = DiffStatus::Bad; | ||||
|             message = Some(err.to_string()) | ||||
|         } | ||||
|         Ok(_) => {} | ||||
|     } | ||||
| 
 | ||||
|     // Compare :path
 | ||||
|     // :path is a quoted string to the absolute path of the document.
 | ||||
| @ -595,12 +470,13 @@ pub fn compare_document<'b, 's>( | ||||
|             if i != 0 { | ||||
|                 return Err("Section cannot be after the first child of document.".into()); | ||||
|             } | ||||
|             child_status.push(compare_section( | ||||
|             child_status.push(compare_ast_node( | ||||
|                 rust.source, | ||||
|                 token, | ||||
|                 rust.zeroth_section | ||||
|                     .as_ref() | ||||
|                     .ok_or("No corresponding zeroth-section")?, | ||||
|                     .ok_or("No corresponding zeroth-section")? | ||||
|                     .into(), | ||||
|             )?); | ||||
|         } else if first_cell == "headline" { | ||||
|             let corresponding_heading = rust | ||||
| @ -608,7 +484,11 @@ pub fn compare_document<'b, 's>( | ||||
|                 .iter() | ||||
|                 .nth(i - rust.zeroth_section.as_ref().map(|_| 1).unwrap_or(0)) | ||||
|                 .ok_or("Should have a corresponding heading.")?; | ||||
|             child_status.push(compare_heading(rust.source, token, corresponding_heading)?); | ||||
|             child_status.push(compare_ast_node( | ||||
|                 rust.source, | ||||
|                 token, | ||||
|                 corresponding_heading.into(), | ||||
|             )?); | ||||
|         } else { | ||||
|             return Err(format!( | ||||
|                 "Document should only contain sections and headlines, found: {}", | ||||
| @ -639,16 +519,8 @@ fn compare_section<'b, 's>( | ||||
|     let mut child_status = Vec::new(); | ||||
|     let mut message = None; | ||||
| 
 | ||||
|     match compare_standard_properties(source, emacs, rust) { | ||||
|         Err(err) => { | ||||
|             this_status = DiffStatus::Bad; | ||||
|             message = Some(err.to_string()) | ||||
|         } | ||||
|         Ok(_) => {} | ||||
|     } | ||||
| 
 | ||||
|     for (emacs_child, rust_child) in children.iter().skip(2).zip(rust.children.iter()) { | ||||
|         child_status.push(compare_element(source, emacs_child, rust_child)?); | ||||
|         child_status.push(compare_ast_node(source, emacs_child, rust_child.into())?); | ||||
|     } | ||||
| 
 | ||||
|     Ok(DiffResult { | ||||
| @ -672,14 +544,6 @@ fn compare_heading<'b, 's>( | ||||
|     let mut this_status = DiffStatus::Good; | ||||
|     let mut message = None; | ||||
| 
 | ||||
|     match compare_standard_properties(source, emacs, rust) { | ||||
|         Err(err) => { | ||||
|             this_status = DiffStatus::Bad; | ||||
|             message = Some(err.to_string()) | ||||
|         } | ||||
|         Ok(_) => {} | ||||
|     } | ||||
| 
 | ||||
|     // Compare level
 | ||||
|     let level = get_property(emacs, ":level")? | ||||
|         .ok_or("Level should not be nil")? | ||||
| @ -756,7 +620,9 @@ fn compare_heading<'b, 's>( | ||||
|                 .as_list()? | ||||
|                 .iter() | ||||
|                 .zip(rust.title.iter()) | ||||
|                 .map(|(emacs_child, rust_child)| compare_object(source, emacs_child, rust_child)) | ||||
|                 .map(|(emacs_child, rust_child)| { | ||||
|                     compare_ast_node(source, emacs_child, rust_child.into()) | ||||
|                 }) | ||||
|                 .collect::<Result<Vec<_>, _>>()?; | ||||
|             child_status.push(artificial_diff_scope("title", title_status)?); | ||||
|         } | ||||
| @ -845,10 +711,10 @@ fn compare_heading<'b, 's>( | ||||
|         .zip(rust.children.iter()) | ||||
|         .map(|(emacs_child, rust_child)| match rust_child { | ||||
|             DocumentElement::Heading(rust_heading) => { | ||||
|                 compare_heading(source, emacs_child, rust_heading) | ||||
|                 compare_ast_node(source, emacs_child, rust_heading.into()) | ||||
|             } | ||||
|             DocumentElement::Section(rust_section) => { | ||||
|                 compare_section(source, emacs_child, rust_section) | ||||
|                 compare_ast_node(source, emacs_child, rust_section.into()) | ||||
|             } | ||||
|         }) | ||||
|         .collect::<Result<Vec<_>, _>>()?; | ||||
| @ -902,7 +768,7 @@ fn compare_paragraph<'b, 's>( | ||||
|     let message = None; | ||||
| 
 | ||||
|     for (emacs_child, rust_child) in children.iter().skip(2).zip(rust.children.iter()) { | ||||
|         child_status.push(compare_object(source, emacs_child, rust_child)?); | ||||
|         child_status.push(compare_ast_node(source, emacs_child, rust_child.into())?); | ||||
|     } | ||||
| 
 | ||||
|     Ok(DiffResult { | ||||
| @ -944,7 +810,7 @@ fn compare_plain_list<'b, 's>( | ||||
|     } | ||||
| 
 | ||||
|     for (emacs_child, rust_child) in children.iter().skip(2).zip(rust.children.iter()) { | ||||
|         child_status.push(compare_plain_list_item(source, emacs_child, rust_child)?); | ||||
|         child_status.push(compare_ast_node(source, emacs_child, rust_child.into())?); | ||||
|     } | ||||
| 
 | ||||
|     Ok(DiffResult { | ||||
| @ -967,14 +833,6 @@ fn compare_plain_list_item<'b, 's>( | ||||
|     let mut child_status = Vec::new(); | ||||
|     let mut this_status = DiffStatus::Good; | ||||
|     let mut message = None; | ||||
|     // This is not called from compare_element so we have to duplicate all the common checks here.
 | ||||
|     match compare_standard_properties(source, emacs, rust) { | ||||
|         Err(err) => { | ||||
|             this_status = DiffStatus::Bad; | ||||
|             message = Some(err.to_string()) | ||||
|         } | ||||
|         Ok(_) => {} | ||||
|     } | ||||
| 
 | ||||
|     // Compare tag
 | ||||
|     let tag = get_property(emacs, ":tag")?; | ||||
| @ -989,7 +847,9 @@ fn compare_plain_list_item<'b, 's>( | ||||
|                 .as_list()? | ||||
|                 .iter() | ||||
|                 .zip(rust.tag.iter()) | ||||
|                 .map(|(emacs_child, rust_child)| compare_object(source, emacs_child, rust_child)) | ||||
|                 .map(|(emacs_child, rust_child)| { | ||||
|                     compare_ast_node(source, emacs_child, rust_child.into()) | ||||
|                 }) | ||||
|                 .collect::<Result<Vec<_>, _>>()?; | ||||
|             child_status.push(artificial_diff_scope("tag", tag_status)?); | ||||
|         } | ||||
| @ -1000,7 +860,7 @@ fn compare_plain_list_item<'b, 's>( | ||||
|         .iter() | ||||
|         .skip(2) | ||||
|         .zip(rust.children.iter()) | ||||
|         .map(|(emacs_child, rust_child)| compare_element(source, emacs_child, rust_child)) | ||||
|         .map(|(emacs_child, rust_child)| compare_ast_node(source, emacs_child, rust_child.into())) | ||||
|         .collect::<Result<Vec<_>, _>>()?; | ||||
|     child_status.push(artificial_diff_scope("contents", contents_status)?); | ||||
| 
 | ||||
| @ -1096,7 +956,7 @@ fn compare_greater_block<'b, 's>( | ||||
|     // Center and quote block has no additional properties
 | ||||
| 
 | ||||
|     for (emacs_child, rust_child) in children.iter().skip(2).zip(rust.children.iter()) { | ||||
|         child_status.push(compare_element(source, emacs_child, rust_child)?); | ||||
|         child_status.push(compare_ast_node(source, emacs_child, rust_child.into())?); | ||||
|     } | ||||
| 
 | ||||
|     Ok(DiffResult { | ||||
| @ -1122,7 +982,7 @@ fn compare_dynamic_block<'b, 's>( | ||||
|     // TODO: Compare :block-name :arguments
 | ||||
| 
 | ||||
|     for (emacs_child, rust_child) in children.iter().skip(2).zip(rust.children.iter()) { | ||||
|         child_status.push(compare_element(source, emacs_child, rust_child)?); | ||||
|         child_status.push(compare_ast_node(source, emacs_child, rust_child.into())?); | ||||
|     } | ||||
| 
 | ||||
|     Ok(DiffResult { | ||||
| @ -1148,7 +1008,7 @@ fn compare_footnote_definition<'b, 's>( | ||||
|     // TODO: Compare :label :pre-blank
 | ||||
| 
 | ||||
|     for (emacs_child, rust_child) in children.iter().skip(2).zip(rust.children.iter()) { | ||||
|         child_status.push(compare_element(source, emacs_child, rust_child)?); | ||||
|         child_status.push(compare_ast_node(source, emacs_child, rust_child.into())?); | ||||
|     } | ||||
| 
 | ||||
|     Ok(DiffResult { | ||||
| @ -1195,7 +1055,7 @@ fn compare_drawer<'b, 's>( | ||||
|     // TODO: Compare :drawer-name
 | ||||
| 
 | ||||
|     for (emacs_child, rust_child) in children.iter().skip(2).zip(rust.children.iter()) { | ||||
|         child_status.push(compare_element(source, emacs_child, rust_child)?); | ||||
|         child_status.push(compare_ast_node(source, emacs_child, rust_child.into())?); | ||||
|     } | ||||
| 
 | ||||
|     Ok(DiffResult { | ||||
| @ -1220,7 +1080,7 @@ fn compare_property_drawer<'b, 's>( | ||||
|     let message = None; | ||||
| 
 | ||||
|     for (emacs_child, rust_child) in children.iter().skip(2).zip(rust.children.iter()) { | ||||
|         child_status.push(compare_node_property(source, emacs_child, rust_child)?); | ||||
|         child_status.push(compare_ast_node(source, emacs_child, rust_child.into())?); | ||||
|     } | ||||
| 
 | ||||
|     Ok(DiffResult { | ||||
| @ -1242,14 +1102,6 @@ fn compare_node_property<'b, 's>( | ||||
|     let child_status = Vec::new(); | ||||
|     let mut this_status = DiffStatus::Good; | ||||
|     let mut message = None; | ||||
|     // This is not called from compare_element so we must duplicate all the tests here.
 | ||||
|     match compare_standard_properties(source, emacs, rust) { | ||||
|         Err(err) => { | ||||
|             this_status = DiffStatus::Bad; | ||||
|             message = Some(err.to_string()) | ||||
|         } | ||||
|         Ok(_) => {} | ||||
|     } | ||||
| 
 | ||||
|     // TODO: Compare :key :value
 | ||||
| 
 | ||||
| @ -1315,7 +1167,7 @@ fn compare_table<'b, 's>( | ||||
|     // TODO: Compare :type :value
 | ||||
| 
 | ||||
|     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)?); | ||||
|         child_status.push(compare_ast_node(source, emacs_child, rust_child.into())?); | ||||
|     } | ||||
| 
 | ||||
|     Ok(DiffResult { | ||||
| @ -1338,21 +1190,13 @@ fn compare_table_row<'b, 's>( | ||||
|     let mut child_status = Vec::new(); | ||||
|     let mut this_status = DiffStatus::Good; | ||||
|     let mut message = None; | ||||
|     // This is not called from compare_element so we must duplicate all the tests here.
 | ||||
|     match compare_standard_properties(source, emacs, rust) { | ||||
|         Err(err) => { | ||||
|             this_status = DiffStatus::Bad; | ||||
|             message = Some(err.to_string()) | ||||
|         } | ||||
|         Ok(_) => {} | ||||
|     } | ||||
| 
 | ||||
|     // TODO: Compare :type
 | ||||
|     //
 | ||||
|     // :type is an unquoted atom of either standard or rule
 | ||||
| 
 | ||||
|     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)?); | ||||
|         child_status.push(compare_ast_node(source, emacs_child, rust_child.into())?); | ||||
|     } | ||||
| 
 | ||||
|     Ok(DiffResult { | ||||
| @ -1375,14 +1219,6 @@ fn compare_table_cell<'b, 's>( | ||||
|     let child_status = Vec::new(); | ||||
|     let mut this_status = DiffStatus::Good; | ||||
|     let mut message = None; | ||||
|     // This is not called from compare_object so we must duplicate all the tests here.
 | ||||
|     match compare_standard_properties(source, emacs, rust) { | ||||
|         Err(err) => { | ||||
|             this_status = DiffStatus::Bad; | ||||
|             message = Some(err.to_string()) | ||||
|         } | ||||
|         Ok(_) => {} | ||||
|     } | ||||
| 
 | ||||
|     for (_emacs_child, _rust_child) in children.iter().skip(2).zip(rust.children.iter()) {} | ||||
| 
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Tom Alexander
						Tom Alexander