diff --git a/matching/src/matching_entry.rs b/matching/src/matching_entry.rs index e1fdc34..a2757e8 100644 --- a/matching/src/matching_entry.rs +++ b/matching/src/matching_entry.rs @@ -6,10 +6,10 @@ pub struct MatchingEntry { impl MatchingEntry { pub fn new(score: usize, is_perfect_match: bool) -> Self { - return MatchingEntry { + MatchingEntry { score, is_perfect_match, - }; + } } } diff --git a/matching/src/ordered_tree_matching.rs b/matching/src/ordered_tree_matching.rs index 3f0247e..da044df 100644 --- a/matching/src/ordered_tree_matching.rs +++ b/matching/src/ordered_tree_matching.rs @@ -4,9 +4,9 @@ use utils::unordered_pair::UnorderedPair; #[derive(PartialEq, Eq, Debug, Clone)] enum Direction { - TOP, - LEFT, - DIAG, + Top, + Left, + Diag, } #[derive(Clone)] @@ -14,7 +14,7 @@ struct Entry<'a>(pub Direction, pub Matchings<'a>); impl<'a> Default for Entry<'a> { fn default() -> Self { - Self(Direction::TOP, Default::default()) + Self(Direction::Top, Default::default()) } } @@ -53,19 +53,17 @@ pub fn ordered_tree_matching<'a>(left: &'a CSTNode, right: &'a CSTNode) -> Match if matrix_m[i][j - 1] > matrix_m[i - 1][j] { if matrix_m[i][j - 1] > matrix_m[i - 1][j - 1] + matching.score { matrix_m[i][j] = matrix_m[i][j - 1]; - matrix_t[i][j] = Entry(Direction::LEFT, w); + matrix_t[i][j] = Entry(Direction::Left, w); } else { matrix_m[i][j] = matrix_m[i - 1][j - 1] + matching.score; - matrix_t[i][j] = Entry(Direction::DIAG, w); + matrix_t[i][j] = Entry(Direction::Diag, w); } + } else if matrix_m[i - 1][j] > matrix_m[i - 1][j - 1] + matching.score { + matrix_m[i][j] = matrix_m[i - 1][j]; + matrix_t[i][j] = Entry(Direction::Top, w); } else { - if matrix_m[i - 1][j] > matrix_m[i - 1][j - 1] + matching.score { - matrix_m[i][j] = matrix_m[i - 1][j]; - matrix_t[i][j] = Entry(Direction::TOP, w); - } else { - matrix_m[i][j] = matrix_m[i - 1][j - 1] + matching.score; - matrix_t[i][j] = Entry(Direction::DIAG, w); - } + matrix_m[i][j] = matrix_m[i - 1][j - 1] + matching.score; + matrix_t[i][j] = Entry(Direction::Diag, w); } } } @@ -80,14 +78,14 @@ pub fn ordered_tree_matching<'a>(left: &'a CSTNode, right: &'a CSTNode) -> Match while i >= 1 && j >= 1 { match matrix_t.get(i).unwrap().get(j).unwrap().0 { - Direction::TOP => i = i - 1, - Direction::LEFT => j = j - 1, - Direction::DIAG => { + Direction::Top => i -= 1, + Direction::Left => j -= 1, + Direction::Diag => { if matrix_m[i][j] > matrix_m[i - 1][j - 1] { matchings.extend(matrix_t[i][j].1.clone()); } - i = i - 1; - j = j - 1; + i -= 1; + j -= 1; } } } @@ -254,7 +252,7 @@ mod tests { end_position: Point { row: 0, column: 7 }, }; let right_child = CSTNode::Terminal { - kind: "kind_c".into(), + kind: "kind_c", value: "value_c".into(), start_position: Point { row: 1, column: 0 }, end_position: Point { row: 1, column: 7 }, @@ -290,7 +288,7 @@ mod tests { end_position: Point { row: 0, column: 7 }, }; let unique_right_child = CSTNode::Terminal { - kind: "kind_c".into(), + kind: "kind_c", value: "value_c".into(), start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, @@ -357,7 +355,7 @@ mod tests { }; let intermediate = CSTNode::NonTerminal { - kind: "intermediate".into(), + kind: "intermediate", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, children: vec![leaf], diff --git a/matching/src/unordered_tree_matching.rs b/matching/src/unordered_tree_matching.rs index d6f41ec..b9d85a7 100644 --- a/matching/src/unordered_tree_matching.rs +++ b/matching/src/unordered_tree_matching.rs @@ -40,7 +40,7 @@ pub fn unordered_tree_matching<'a>(left: &'a CSTNode, right: &'a CSTNode) -> cra for child_left in children_left { for child_right in children_right { - let matching_score = compute_matching_score(&child_left, &child_right); + let matching_score = compute_matching_score(child_left, child_right); if matching_score == 1 { let child_matching = calculate_matchings(child_left, child_right); diff --git a/merge/src/merged_cst_node.rs b/merge/src/merged_cst_node.rs index 0f35fa3..4f4a505 100644 --- a/merge/src/merged_cst_node.rs +++ b/merge/src/merged_cst_node.rs @@ -16,9 +16,9 @@ pub enum MergedCSTNode<'a> { }, } -impl<'a> Into> for CSTNode<'a> { - fn into(self) -> MergedCSTNode<'a> { - match self { +impl<'a> From> for MergedCSTNode<'a> { + fn from(val: CSTNode<'a>) -> Self { + match val { CSTNode::Terminal { kind, value, .. } => MergedCSTNode::Terminal { kind, value }, CSTNode::NonTerminal { kind, children, .. } => MergedCSTNode::NonTerminal { kind, @@ -35,7 +35,7 @@ impl ToString for MergedCSTNode<'_> { MergedCSTNode::NonTerminal { children, .. } => { children.iter().fold(String::new(), |acc, current| { let mut result = acc.to_owned(); - result.push_str(" "); + result.push(' '); result.push_str(¤t.clone().to_string()); result }) diff --git a/merge/src/odered_merge.rs b/merge/src/odered_merge.rs index 3c82aff..f0072ca 100644 --- a/merge/src/odered_merge.rs +++ b/merge/src/odered_merge.rs @@ -30,7 +30,7 @@ pub fn ordered_merge<'a>( base.to_owned().into() // Changed in both } else if value_left != value_base && value_right != value_base { - match diffy::merge(&value_base, &value_left, &value_right) { + match diffy::merge(value_base, value_left, value_right) { Ok(value) => MergedCSTNode::Terminal { kind, value }, Err(value) => MergedCSTNode::Terminal { kind, value }, } @@ -81,12 +81,12 @@ pub fn ordered_merge<'a>( ) { (true, Some(_), Some(_), Some(_), Some(_)) => { result_children.push(crate::merge( - &cur_left.unwrap(), - &cur_left.unwrap(), - &cur_right.unwrap(), - &base_left_matchings, - &base_right_matchings, - &left_right_matchings, + cur_left.unwrap(), + cur_left.unwrap(), + cur_right.unwrap(), + base_left_matchings, + base_right_matchings, + left_right_matchings, )); cur_left = children_left_it.next(); @@ -94,12 +94,12 @@ pub fn ordered_merge<'a>( } (true, Some(_), None, Some(_), None) => { result_children.push(crate::merge( - &cur_left.unwrap(), - &cur_left.unwrap(), - &cur_right.unwrap(), - &base_left_matchings, - &base_right_matchings, - &left_right_matchings, + cur_left.unwrap(), + cur_left.unwrap(), + cur_right.unwrap(), + base_left_matchings, + base_right_matchings, + left_right_matchings, )); cur_left = children_left_it.next(); @@ -123,7 +123,7 @@ pub fn ordered_merge<'a>( (false, Some(_), None, None, Some(matching_base_right)) => { if !matching_base_right.is_perfect_match { result_children.push(MergedCSTNode::Conflict { - left: None.into(), + left: None, right: Some(Box::new(cur_right.unwrap().to_owned().into())), }) } @@ -147,7 +147,7 @@ pub fn ordered_merge<'a>( if !matching_base_left.is_perfect_match { result_children.push(MergedCSTNode::Conflict { left: Some(Box::new(cur_left.unwrap().to_owned().into())), - right: None.into(), + right: None, }) } cur_left = children_left_it.next(); @@ -160,10 +160,10 @@ pub fn ordered_merge<'a>( (true, true) => {} (true, false) => result_children.push(MergedCSTNode::Conflict { left: Some(Box::new(cur_left.unwrap().to_owned().into())), - right: None.into(), + right: None, }), (false, true) => result_children.push(MergedCSTNode::Conflict { - left: None.into(), + left: None, right: Some(Box::new(cur_right.unwrap().to_owned().into())), }), (false, false) => result_children.push(MergedCSTNode::Conflict { @@ -262,22 +262,22 @@ mod tests { parent_b: &CSTNode, expected_merge: &MergedCSTNode, ) { - let matchings_base_parent_a = ordered_tree_matching(&base, &parent_a); - let matchings_base_parent_b = ordered_tree_matching(&base, &parent_b); - let matchings_parents = ordered_tree_matching(&parent_a, &parent_b); + let matchings_base_parent_a = ordered_tree_matching(base, parent_a); + let matchings_base_parent_b = ordered_tree_matching(base, parent_b); + let matchings_parents = ordered_tree_matching(parent_a, parent_b); let merged_tree = ordered_merge( - &base, - &parent_a, - &parent_b, + base, + parent_a, + parent_b, &matchings_base_parent_a, &matchings_base_parent_b, &matchings_parents, ); let merged_tree_swap = ordered_merge( - &base, - &parent_b, - &parent_a, + base, + parent_b, + parent_a, &matchings_base_parent_b, &matchings_base_parent_a, &matchings_parents, @@ -293,14 +293,14 @@ mod tests { parent_b: &CSTNode, expected_merge: &MergedCSTNode, ) { - let matchings_base_parent_a = ordered_tree_matching(&base, &parent_a); - let matchings_base_parent_b = ordered_tree_matching(&base, &parent_b); - let matchings_parents = ordered_tree_matching(&parent_a, &parent_b); + let matchings_base_parent_a = ordered_tree_matching(base, parent_a); + let matchings_base_parent_b = ordered_tree_matching(base, parent_b); + let matchings_parents = ordered_tree_matching(parent_a, parent_b); let merged_tree = ordered_merge( - &base, - &parent_a, - &parent_b, + base, + parent_a, + parent_b, &matchings_base_parent_a, &matchings_base_parent_b, &matchings_parents, @@ -312,7 +312,7 @@ mod tests { #[test] fn if_i_am_merging_three_unchanged_nodes_it_is_a_success() { let node = CSTNode::Terminal { - kind: "kind".into(), + kind: "kind", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, value: "value".into(), @@ -329,19 +329,19 @@ mod tests { #[test] fn returns_success_if_there_are_changes_in_both_parents_and_they_are_not_conflicting() { let base = CSTNode::Terminal { - kind: "kind".into(), + kind: "kind", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, value: "\nvalue\n".into(), }; let left = CSTNode::Terminal { - kind: "kind".into(), + kind: "kind", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, value: "left\nvalue\n".into(), }; let right = CSTNode::Terminal { - kind: "kind".into(), + kind: "kind", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, value: "\nvalue\nright".into(), @@ -352,7 +352,7 @@ mod tests { &left, &right, &MergedCSTNode::Terminal { - kind: "kind".into(), + kind: "kind", value: "left\nvalue\nright".into(), }, ) @@ -361,19 +361,19 @@ mod tests { #[test] fn returns_conflict_if_there_are_changes_in_both_parents_and_they_are_conflicting() { let base = CSTNode::Terminal { - kind: "kind".into(), + kind: "kind", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, value: "value".into(), }; let left = CSTNode::Terminal { - kind: "kind".into(), + kind: "kind", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, value: "left_value".into(), }; let right = CSTNode::Terminal { - kind: "kind".into(), + kind: "kind", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, value: "right_value".into(), @@ -383,7 +383,7 @@ mod tests { ordered_merge(&base, &left, &right, &Matchings::empty(), &Matchings::empty(), &Matchings::empty()), MergedCSTNode::Terminal { - kind: "kind".into(), + kind: "kind", value: "<<<<<<< ours\nleft_value||||||| original\nvalue=======\nright_value>>>>>>> theirs\n".into() } ) @@ -392,13 +392,13 @@ mod tests { #[test] fn if_there_is_a_change_only_in_one_parent_it_returns_the_changes_from_this_parent() { let base_and_left = CSTNode::Terminal { - kind: "kind".into(), + kind: "kind", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, value: "value".into(), }; let changed_parent = CSTNode::Terminal { - kind: "kind".into(), + kind: "kind", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, value: "value_right".into(), @@ -417,19 +417,19 @@ mod tests { fn test_can_not_merge_terminal_with_non_terminal() { ordered_merge( &CSTNode::Terminal { - kind: "kind".into(), + kind: "kind", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, value: "value".into(), }, &CSTNode::Terminal { - kind: "kind".into(), + kind: "kind", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, value: "value".into(), }, &CSTNode::NonTerminal { - kind: "kind".into(), + kind: "kind", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, children: vec![], @@ -443,18 +443,18 @@ mod tests { #[test] fn it_merges_non_terminals_if_there_are_non_changes() { let tree = CSTNode::NonTerminal { - kind: "kind".into(), + kind: "kind", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, children: vec![ CSTNode::Terminal { - kind: "kind_a".into(), + kind: "kind_a", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, value: "value_a".into(), }, CSTNode::Terminal { - kind: "kind_b".into(), + kind: "kind_b", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, value: "value_b".into(), @@ -473,24 +473,24 @@ mod tests { #[test] fn it_merges_non_terminals_if_both_left_and_right_add_the_same_things() { let base = CSTNode::NonTerminal { - kind: "kind".into(), + kind: "kind", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, children: vec![], }; let parent = CSTNode::NonTerminal { - kind: "kind".into(), + kind: "kind", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, children: vec![ CSTNode::Terminal { - kind: "kind_a".into(), + kind: "kind_a", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, value: "value_a".into(), }, CSTNode::Terminal { - kind: "kind_b".into(), + kind: "kind_b", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, value: "value_b".into(), @@ -510,25 +510,25 @@ mod tests { fn it_merges_non_terminals_if_only_one_parent_adds_a_node_in_an_initially_empty_children_list() { let base = CSTNode::NonTerminal { - kind: "kind".into(), + kind: "kind", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, children: vec![], }; let initially_empty_parent = CSTNode::NonTerminal { - kind: "kind".into(), + kind: "kind", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, children: vec![], }; let parent_that_added = CSTNode::NonTerminal { - kind: "kind".into(), + kind: "kind", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, children: vec![CSTNode::Terminal { - kind: "kind_a".into(), + kind: "kind_a", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, value: "value_a".into(), @@ -536,9 +536,9 @@ mod tests { }; let expected_merge = MergedCSTNode::NonTerminal { - kind: "kind".into(), + kind: "kind", children: vec![MergedCSTNode::Terminal { - kind: "kind_a".into(), + kind: "kind_a", value: "value_a".into(), }], }; @@ -554,11 +554,11 @@ mod tests { #[test] fn it_merges_non_terminals_if_only_one_parent_adds_a_node_in_non_empty_children_list() { let base = CSTNode::NonTerminal { - kind: "kind".into(), + kind: "kind", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, children: vec![CSTNode::Terminal { - kind: "kind_a".into(), + kind: "kind_a", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, value: "value_a".into(), @@ -566,11 +566,11 @@ mod tests { }; let unchanged_parent = CSTNode::NonTerminal { - kind: "kind".into(), + kind: "kind", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, children: vec![CSTNode::Terminal { - kind: "kind_a".into(), + kind: "kind_a", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, value: "value_a".into(), @@ -578,18 +578,18 @@ mod tests { }; let parent_that_added = CSTNode::NonTerminal { - kind: "kind".into(), + kind: "kind", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, children: vec![ CSTNode::Terminal { - kind: "kind_a".into(), + kind: "kind_a", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, value: "value_a".into(), }, CSTNode::Terminal { - kind: "kind_b".into(), + kind: "kind_b", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, value: "value_b".into(), @@ -598,14 +598,14 @@ mod tests { }; let merge = MergedCSTNode::NonTerminal { - kind: "kind".into(), + kind: "kind", children: vec![ MergedCSTNode::Terminal { - kind: "kind_a".into(), + kind: "kind_a", value: "value_a".into(), }, MergedCSTNode::Terminal { - kind: "kind_b".into(), + kind: "kind_b", value: "value_b".into(), }, ], @@ -622,11 +622,11 @@ mod tests { #[test] fn it_merges_when_one_parent_adds_a_node_and_removes_one_that_was_not_edited_in_the_other() { let base = CSTNode::NonTerminal { - kind: "kind".into(), + kind: "kind", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, children: vec![CSTNode::Terminal { - kind: "kind_a".into(), + kind: "kind_a", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, value: "value_a".into(), @@ -634,11 +634,11 @@ mod tests { }; let changed_parent = CSTNode::NonTerminal { - kind: "kind".into(), + kind: "kind", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, children: vec![CSTNode::Terminal { - kind: "kind_b".into(), + kind: "kind_b", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, value: "value_b".into(), @@ -646,11 +646,11 @@ mod tests { }; let unchanged_parent = CSTNode::NonTerminal { - kind: "kind".into(), + kind: "kind", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, children: vec![CSTNode::Terminal { - kind: "kind_a".into(), + kind: "kind_a", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, value: "value_a".into(), @@ -676,15 +676,15 @@ mod tests { #[test] fn it_merges_when_one_parent_adds_a_node_and_removes_from_another_that_was_changed() { let base = CSTNode::NonTerminal { - kind: "kind".into(), + kind: "kind", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, children: vec![CSTNode::NonTerminal { - kind: "subtree".into(), + kind: "subtree", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, children: vec![CSTNode::Terminal { - kind: "kind_a".into(), + kind: "kind_a", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, value: "value_a".into(), @@ -693,15 +693,15 @@ mod tests { }; let parent_a = CSTNode::NonTerminal { - kind: "kind".into(), + kind: "kind", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, children: vec![CSTNode::NonTerminal { - kind: "another_subtree".into(), + kind: "another_subtree", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, children: vec![CSTNode::Terminal { - kind: "kind_b".into(), + kind: "kind_b", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, value: "value_b".into(), @@ -710,15 +710,15 @@ mod tests { }; let parent_b = CSTNode::NonTerminal { - kind: "kind".into(), + kind: "kind", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, children: vec![CSTNode::NonTerminal { - kind: "subtree".into(), + kind: "subtree", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, children: vec![CSTNode::Terminal { - kind: "kind_c".into(), + kind: "kind_c", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, value: "value_c".into(), @@ -749,21 +749,21 @@ mod tests { assert_eq!( MergedCSTNode::NonTerminal { - kind: "kind".into(), + kind: "kind", children: vec![ MergedCSTNode::NonTerminal { - kind: "another_subtree".into(), + kind: "another_subtree", children: vec![MergedCSTNode::Terminal { - kind: "kind_b".into(), + kind: "kind_b", value: "value_b".into(), }], }, MergedCSTNode::Conflict { left: None, right: Some(Box::new(MergedCSTNode::NonTerminal { - kind: "subtree".into(), + kind: "subtree", children: vec![MergedCSTNode::Terminal { - kind: "kind_c".into(), + kind: "kind_c", value: "value_c".into(), }], })), @@ -775,20 +775,20 @@ mod tests { assert_eq!( MergedCSTNode::NonTerminal { - kind: "kind".into(), + kind: "kind", children: vec![ MergedCSTNode::NonTerminal { - kind: "another_subtree".into(), + kind: "another_subtree", children: vec![MergedCSTNode::Terminal { - kind: "kind_b".into(), + kind: "kind_b", value: "value_b".into(), }], }, MergedCSTNode::Conflict { left: Some(Box::new(MergedCSTNode::NonTerminal { - kind: "subtree".into(), + kind: "subtree", children: vec![MergedCSTNode::Terminal { - kind: "kind_c".into(), + kind: "kind_c", value: "value_c".into(), }], })), @@ -803,18 +803,18 @@ mod tests { #[test] fn if_both_parents_add_different_nodes_then_we_have_a_conflict() { let base = CSTNode::NonTerminal { - kind: "kind".into(), + kind: "kind", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, children: vec![], }; let left = CSTNode::NonTerminal { - kind: "kind".into(), + kind: "kind", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, children: vec![CSTNode::Terminal { - kind: "kind_a".into(), + kind: "kind_a", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, value: "value_a".into(), @@ -822,11 +822,11 @@ mod tests { }; let right = CSTNode::NonTerminal { - kind: "kind".into(), + kind: "kind", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, children: vec![CSTNode::Terminal { - kind: "kind_b".into(), + kind: "kind_b", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, value: "value_b".into(), @@ -838,14 +838,14 @@ mod tests { &left, &right, &MergedCSTNode::NonTerminal { - kind: "kind".into(), + kind: "kind", children: vec![MergedCSTNode::Conflict { left: Some(Box::new(MergedCSTNode::Terminal { - kind: "kind_a".into(), + kind: "kind_a", value: "value_a".into(), })), right: Some(Box::new(MergedCSTNode::Terminal { - kind: "kind_b".into(), + kind: "kind_b", value: "value_b".into(), })), }], @@ -856,18 +856,18 @@ mod tests { #[test] fn it_merges_when_one_parent_removes_a_node_that_was_not_changed_in_another_parent() { let base = CSTNode::NonTerminal { - kind: "kind".into(), + kind: "kind", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, children: vec![ CSTNode::Terminal { - kind: "kind_a".into(), + kind: "kind_a", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, value: "value_a".into(), }, CSTNode::Terminal { - kind: "kind_b".into(), + kind: "kind_b", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, value: "value_b".into(), @@ -876,18 +876,18 @@ mod tests { }; let left = CSTNode::NonTerminal { - kind: "kind".into(), + kind: "kind", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, children: vec![ CSTNode::Terminal { - kind: "kind_a".into(), + kind: "kind_a", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, value: "value_a".into(), }, CSTNode::Terminal { - kind: "kind_b".into(), + kind: "kind_b", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, value: "value_b".into(), @@ -896,11 +896,11 @@ mod tests { }; let right = CSTNode::NonTerminal { - kind: "kind".into(), + kind: "kind", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, children: vec![CSTNode::Terminal { - kind: "kind_b".into(), + kind: "kind_b", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, value: "value_b".into(), @@ -908,9 +908,9 @@ mod tests { }; let expected_merge = MergedCSTNode::NonTerminal { - kind: "kind".into(), + kind: "kind", children: vec![MergedCSTNode::Terminal { - kind: "kind_b".into(), + kind: "kind_b", value: "value_b".into(), }], }; @@ -921,23 +921,23 @@ mod tests { #[test] fn it_detects_a_conflict_when_one_parent_removes_a_node_that_was_changed_in_another_parent() { let base = CSTNode::NonTerminal { - kind: "kind".into(), + kind: "kind", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, children: vec![ CSTNode::NonTerminal { - kind: "subtree".into(), + kind: "subtree", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, children: vec![CSTNode::Terminal { - kind: "kind_b".into(), + kind: "kind_b", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, value: "value_b".into(), }], }, CSTNode::Terminal { - kind: "kind_a".into(), + kind: "kind_a", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, value: "value_a".into(), @@ -946,23 +946,23 @@ mod tests { }; let left = CSTNode::NonTerminal { - kind: "kind".into(), + kind: "kind", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, children: vec![ CSTNode::NonTerminal { - kind: "subtree".into(), + kind: "subtree", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, children: vec![CSTNode::Terminal { - kind: "kind_c".into(), + kind: "kind_c", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, value: "value_c".into(), }], }, CSTNode::Terminal { - kind: "kind_a".into(), + kind: "kind_a", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, value: "value_a".into(), @@ -971,11 +971,11 @@ mod tests { }; let right = CSTNode::NonTerminal { - kind: "kind".into(), + kind: "kind", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, children: vec![CSTNode::Terminal { - kind: "kind_a".into(), + kind: "kind_a", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, value: "value_a".into(), @@ -1036,18 +1036,18 @@ mod tests { #[test] fn it_merges_when_a_parent_adds_a_node() { let base = CSTNode::NonTerminal { - kind: "kind".into(), + kind: "kind", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, children: vec![ CSTNode::Terminal { - kind: "kind_a".into(), + kind: "kind_a", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, value: "value_a".into(), }, CSTNode::Terminal { - kind: "kind_c".into(), + kind: "kind_c", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, value: "value_c".into(), @@ -1056,18 +1056,18 @@ mod tests { }; let unchanged_parent = CSTNode::NonTerminal { - kind: "kind".into(), + kind: "kind", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, children: vec![ CSTNode::Terminal { - kind: "kind_a".into(), + kind: "kind_a", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, value: "value_a".into(), }, CSTNode::Terminal { - kind: "kind_c".into(), + kind: "kind_c", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, value: "value_c".into(), @@ -1076,24 +1076,24 @@ mod tests { }; let changed_parent = CSTNode::NonTerminal { - kind: "kind".into(), + kind: "kind", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, children: vec![ CSTNode::Terminal { - kind: "kind_a".into(), + kind: "kind_a", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, value: "value_a".into(), }, CSTNode::Terminal { - kind: "kind_b".into(), + kind: "kind_b", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, value: "value_b".into(), }, CSTNode::Terminal { - kind: "kind_c".into(), + kind: "kind_c", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, value: "value_c".into(), @@ -1130,11 +1130,11 @@ mod tests { #[test] fn it_merges_when_one_parent_removes_and_add_a_node() { let base = CSTNode::NonTerminal { - kind: "kind".into(), + kind: "kind", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, children: vec![CSTNode::Terminal { - kind: "kind_b".into(), + kind: "kind_b", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, value: "value_b".into(), @@ -1142,7 +1142,7 @@ mod tests { }; let parent_a = CSTNode::NonTerminal { - kind: "kind".into(), + kind: "kind", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, children: vec![CSTNode::Terminal { @@ -1154,12 +1154,12 @@ mod tests { }; let parent_b = CSTNode::NonTerminal { - kind: "kind".into(), + kind: "kind", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, children: vec![ CSTNode::Terminal { - kind: "kind_b".into(), + kind: "kind_b", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, value: "value_b".into(), @@ -1209,7 +1209,7 @@ mod tests { }; let parent_a = CSTNode::NonTerminal { - kind: "kind".into(), + kind: "kind", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, children: vec![CSTNode::Terminal { @@ -1221,7 +1221,7 @@ mod tests { }; let parent_b = CSTNode::NonTerminal { - kind: "kind".into(), + kind: "kind", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, children: vec![ @@ -1317,7 +1317,7 @@ mod tests { }; let parent_b = CSTNode::NonTerminal { - kind: "kind".into(), + kind: "kind", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, children: vec![ @@ -1393,7 +1393,7 @@ mod tests { }; let parent_b = CSTNode::NonTerminal { - kind: "kind".into(), + kind: "kind", start_position: Point { row: 0, column: 0 }, end_position: Point { row: 0, column: 7 }, children: vec![CSTNode::Terminal { diff --git a/model/src/cst_node.rs b/model/src/cst_node.rs index 16c2374..7ba9f58 100644 --- a/model/src/cst_node.rs +++ b/model/src/cst_node.rs @@ -24,7 +24,7 @@ impl CSTNode<'_> { pub fn are_children_unordered(&self) -> bool { match self { CSTNode::Terminal { .. } => false, - CSTNode::NonTerminal { kind, .. } => vec!["interface_body"].contains(kind), + CSTNode::NonTerminal { kind, .. } => ["interface_body"].contains(kind), } } } @@ -36,7 +36,7 @@ impl ToString for CSTNode<'_> { CSTNode::NonTerminal { children, .. } => { children.iter().fold(String::new(), |acc, current| { let mut result = acc.to_owned(); - result.push_str(" "); + result.push(' '); result.push_str(¤t.clone().to_string()); result }) diff --git a/parsing/src/parse.rs b/parsing/src/parse.rs index 37fc65a..c0ba05e 100644 --- a/parsing/src/parse.rs +++ b/parsing/src/parse.rs @@ -5,7 +5,7 @@ use tree_sitter::Node; fn explore_node<'a>(node: Node, src: &'a str, config: &'a ParserConfiguration) -> CSTNode<'a> { if node.child_count() == 0 || config.stop_compilation_at.contains(node.kind()) { CSTNode::Terminal { - kind: node.kind().into(), + kind: node.kind(), start_position: Point { row: node.start_position().row, column: node.start_position().column }, end_position: Point { row: node.end_position().row, column: node.end_position().column }, value: src[node.byte_range()].into(), @@ -13,7 +13,7 @@ fn explore_node<'a>(node: Node, src: &'a str, config: &'a ParserConfiguration) - } else { let mut cursor = node.walk(); CSTNode::NonTerminal { - kind: node.kind().into(), + kind: node.kind(), start_position: Point { row: node.start_position().row, column: node.start_position().column }, end_position: Point { row: node.end_position().row, column: node.end_position().column }, children: node