From e39562c85d342591b66c87fde7bbbf2a8c1ade71 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Mon, 9 Oct 2023 13:08:45 -0400 Subject: [PATCH] Roll out the new children functions to all compare functions using the new compare_properties macro. We will roll it out to the rest of them when we move them over to the new compare_properties macro. --- src/compare/diff.rs | 103 +++++++++++++++++++++++++++++--------------- 1 file changed, 68 insertions(+), 35 deletions(-) diff --git a/src/compare/diff.rs b/src/compare/diff.rs index f76efd7..c615290 100644 --- a/src/compare/diff.rs +++ b/src/compare/diff.rs @@ -2584,20 +2584,24 @@ fn compare_bold<'b, 's>( emacs: &'b Token<'s>, rust: &'b Bold<'s>, ) -> Result, Box> { - let children = emacs.as_list()?; let mut this_status = DiffStatus::Good; let mut child_status = Vec::new(); let mut message = None; + compare_children( + source, + emacs, + &rust.children, + &mut child_status, + &mut this_status, + &mut message, + )?; + if let Some((new_status, new_message)) = compare_properties!(emacs)? { this_status = new_status; message = new_message; } - for (emacs_child, rust_child) in children.iter().skip(2).zip(rust.children.iter()) { - child_status.push(compare_ast_node(source, emacs_child, rust_child.into())?); - } - Ok(DiffResult { status: this_status, name: rust.get_elisp_name(), @@ -2614,20 +2618,24 @@ fn compare_italic<'b, 's>( emacs: &'b Token<'s>, rust: &'b Italic<'s>, ) -> Result, Box> { - let children = emacs.as_list()?; let mut this_status = DiffStatus::Good; let mut child_status = Vec::new(); let mut message = None; + compare_children( + source, + emacs, + &rust.children, + &mut child_status, + &mut this_status, + &mut message, + )?; + if let Some((new_status, new_message)) = compare_properties!(emacs)? { this_status = new_status; message = new_message; } - for (emacs_child, rust_child) in children.iter().skip(2).zip(rust.children.iter()) { - child_status.push(compare_ast_node(source, emacs_child, rust_child.into())?); - } - Ok(DiffResult { status: this_status, name: rust.get_elisp_name(), @@ -2644,20 +2652,24 @@ fn compare_underline<'b, 's>( emacs: &'b Token<'s>, rust: &'b Underline<'s>, ) -> Result, Box> { - let children = emacs.as_list()?; let mut this_status = DiffStatus::Good; let mut child_status = Vec::new(); let mut message = None; + compare_children( + source, + emacs, + &rust.children, + &mut child_status, + &mut this_status, + &mut message, + )?; + if let Some((new_status, new_message)) = compare_properties!(emacs)? { this_status = new_status; message = new_message; } - for (emacs_child, rust_child) in children.iter().skip(2).zip(rust.children.iter()) { - child_status.push(compare_ast_node(source, emacs_child, rust_child.into())?); - } - Ok(DiffResult { status: this_status, name: rust.get_elisp_name(), @@ -2677,6 +2689,8 @@ fn compare_verbatim<'b, 's>( let mut this_status = DiffStatus::Good; let mut message = None; + assert_no_children(emacs, &mut this_status, &mut message)?; + if let Some((new_status, new_message)) = compare_properties!( emacs, rust, @@ -2709,6 +2723,8 @@ fn compare_code<'b, 's>( let mut this_status = DiffStatus::Good; let mut message = None; + assert_no_children(emacs, &mut this_status, &mut message)?; + if let Some((new_status, new_message)) = compare_properties!( emacs, rust, @@ -2738,20 +2754,24 @@ fn compare_strike_through<'b, 's>( emacs: &'b Token<'s>, rust: &'b StrikeThrough<'s>, ) -> Result, Box> { - let children = emacs.as_list()?; let mut this_status = DiffStatus::Good; let mut child_status = Vec::new(); let mut message = None; + compare_children( + source, + emacs, + &rust.children, + &mut child_status, + &mut this_status, + &mut message, + )?; + if let Some((new_status, new_message)) = compare_properties!(emacs)? { this_status = new_status; message = new_message; } - for (emacs_child, rust_child) in children.iter().skip(2).zip(rust.children.iter()) { - child_status.push(compare_ast_node(source, emacs_child, rust_child.into())?); - } - Ok(DiffResult { status: this_status, name: rust.get_elisp_name(), @@ -2768,11 +2788,19 @@ fn compare_regular_link<'b, 's>( emacs: &'b Token<'s>, rust: &'b RegularLink<'s>, ) -> Result, Box> { - let children = emacs.as_list()?; let mut this_status = DiffStatus::Good; let mut child_status = Vec::new(); let mut message = None; + compare_children( + source, + emacs, + &rust.children, + &mut child_status, + &mut this_status, + &mut message, + )?; + if let Some((new_status, new_message)) = compare_properties!( emacs, rust, @@ -2820,10 +2848,6 @@ fn compare_regular_link<'b, 's>( message = new_message; } - for (emacs_child, rust_child) in children.iter().skip(2).zip(rust.children.iter()) { - child_status.push(compare_ast_node(source, emacs_child, rust_child.into())?); - } - Ok(DiffResult { status: this_status, name: rust.get_elisp_name(), @@ -2840,11 +2864,19 @@ fn compare_radio_link<'b, 's>( emacs: &'b Token<'s>, rust: &'b RadioLink<'s>, ) -> Result, Box> { - let children = emacs.as_list()?; let mut this_status = DiffStatus::Good; let mut child_status = Vec::new(); let mut message = None; + compare_children( + source, + emacs, + &rust.children, + &mut child_status, + &mut this_status, + &mut message, + )?; + if let Some((new_status, new_message)) = compare_properties!( emacs, rust, @@ -2883,10 +2915,6 @@ fn compare_radio_link<'b, 's>( message = new_message; } - for (emacs_child, rust_child) in children.iter().skip(2).zip(rust.children.iter()) { - child_status.push(compare_ast_node(source, emacs_child, rust_child.into())?); - } - Ok(DiffResult { status: this_status, name: rust.get_elisp_name(), @@ -2903,7 +2931,6 @@ fn compare_radio_target<'b, 's>( emacs: &'b Token<'s>, rust: &'b RadioTarget<'s>, ) -> Result, Box> { - let children = emacs.as_list()?; let mut this_status = DiffStatus::Good; let mut child_status = Vec::new(); let mut message = None; @@ -2930,10 +2957,6 @@ fn compare_radio_target<'b, 's>( message = new_message; } - for (emacs_child, rust_child) in children.iter().skip(2).zip(rust.children.iter()) { - child_status.push(compare_ast_node(source, emacs_child, rust_child.into())?); - } - Ok(DiffResult { status: this_status, name: rust.get_elisp_name(), @@ -2953,6 +2976,8 @@ fn compare_plain_link<'b, 's>( let mut this_status = DiffStatus::Good; let mut message = None; + assert_no_children(emacs, &mut this_status, &mut message)?; + if let Some((new_status, new_message)) = compare_properties!( emacs, rust, @@ -3019,6 +3044,8 @@ fn compare_angle_link<'b, 's>( let mut this_status = DiffStatus::Good; let mut message = None; + assert_no_children(emacs, &mut this_status, &mut message)?; + if let Some((new_status, new_message)) = compare_properties!( emacs, rust, @@ -3085,6 +3112,8 @@ fn compare_org_macro<'b, 's>( let mut this_status = DiffStatus::Good; let mut message = None; + assert_no_children(emacs, &mut this_status, &mut message)?; + if let Some((new_status, new_message)) = compare_properties!( emacs, rust, @@ -3131,6 +3160,8 @@ fn compare_entity<'b, 's>( let mut this_status = DiffStatus::Good; let mut message = None; + assert_no_children(emacs, &mut this_status, &mut message)?; + if let Some((new_status, new_message)) = compare_properties!( emacs, rust, @@ -3199,6 +3230,8 @@ fn compare_latex_fragment<'b, 's>( let mut this_status = DiffStatus::Good; let mut message = None; + assert_no_children(emacs, &mut this_status, &mut message)?; + if let Some((new_status, new_message)) = compare_properties!( emacs, rust,