Skip to content

Commit

Permalink
Add match_final
Browse files Browse the repository at this point in the history
  • Loading branch information
JayXon committed Feb 1, 2024
1 parent d2d88c0 commit 91c9154
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,9 @@ fn find_binary_operators(
Some(o) => matcher.match_one(i, o),
None => false,
})
&& matcher.match_final(Some(el), er, op_idx)
{
println!("{}{}{}", el, op_idx, er);
println!("{el}{op_idx}{er}");
}
} else if let Some(output) = op.vec_apply(el.output.clone(), &er.output) {
save(
Expand Down Expand Up @@ -206,8 +207,9 @@ fn find_unary_operators(
.iter()
.enumerate()
.all(|(i, &or)| matcher.match_one(i, (op.apply)(or)))
&& matcher.match_final(None, er, op_idx)
{
println!("{}{}", op_idx, er);
println!("{op_idx}{er}");
}
} else {
save(
Expand Down
10 changes: 10 additions & 0 deletions src/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,21 @@ impl Matcher {
output == GOAL[index]
}

// Will be called after match_one returns true for all outputs
pub fn match_final(&mut self, _el: Option<&Expr>, _er: &Expr, _op: OpIndex) -> bool {
true
}

pub fn match_all(&mut self, expr: &Expr) -> bool {
expr.output
.iter()
.enumerate()
.all(|(i, &o)| self.match_one(i, o))
&& self.match_final(
expr.left.map(|e| unsafe { e.as_ref() }),
unsafe { expr.right.unwrap().as_ref() },
expr.op_idx,
)
}
}

Expand Down

0 comments on commit 91c9154

Please sign in to comment.