Skip to content

Commit

Permalink
refactor: Push conflicting logic into domain
Browse files Browse the repository at this point in the history
  • Loading branch information
jpedroh committed Dec 6, 2023
1 parent 4b3cff9 commit 111967e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
12 changes: 1 addition & 11 deletions bin/src/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,8 @@ pub fn run_tool_on_merge_scenario(
&matchings_left_right,
);

match has_conflict(&result) {
match result.has_conflict() {
true => Ok(ExecutionResult::WithConflicts(result.to_string())),
false => Ok(ExecutionResult::WithoutConflicts(result.to_string())),
}
}

fn has_conflict(result: &merge::MergedCSTNode) -> bool {
match result {
merge::MergedCSTNode::NonTerminal { children, .. } => {
children.iter().any(|child| has_conflict(child))
}
merge::MergedCSTNode::Terminal { .. } => false,
merge::MergedCSTNode::Conflict { .. } => true,
}
}
12 changes: 12 additions & 0 deletions merge/src/merged_cst_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,15 @@ impl ToString for MergedCSTNode<'_> {
}
}
}

impl MergedCSTNode<'_> {
pub fn has_conflict(&self) -> bool {
match self {
MergedCSTNode::NonTerminal { children, .. } => {
children.iter().any(|child| child.has_conflict())
}
MergedCSTNode::Terminal { .. } => false,
MergedCSTNode::Conflict { .. } => true,
}
}
}

0 comments on commit 111967e

Please sign in to comment.