Skip to content

Commit

Permalink
Implement a convenience method on fol::Comparison that returns the in…
Browse files Browse the repository at this point in the history
…dividual comparisons
  • Loading branch information
teiesti authored and ZachJHansen committed Nov 21, 2024
1 parent 17b05bb commit a2c43eb
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/syntax_tree/fol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,36 @@ pub struct Comparison {
impl_node!(Comparison, Format, ComparisonParser);

impl Comparison {
pub fn individuals(&self) -> impl Iterator<Item = (&GeneralTerm, &Relation, &GeneralTerm)> {
struct Individuals<'a> {
lhs: &'a GeneralTerm,
guards_iter: std::slice::Iter<'a, Guard>,
}

impl<'a> Iterator for Individuals<'a> {
type Item = (&'a GeneralTerm, &'a Relation, &'a GeneralTerm);

fn next(&mut self) -> Option<Self::Item> {
if let Some(Guard {
relation,
term: rhs,
}) = self.guards_iter.next()
{
let result = Some((self.lhs, relation, rhs));
self.lhs = rhs;
result
} else {
None
}
}
}

Individuals {
lhs: &self.term,
guards_iter: self.guards.iter(),
}
}

pub fn substitute(self, var: Variable, term: GeneralTerm) -> Self {
let lhs = self.term.substitute(var.clone(), term.clone());

Expand Down

0 comments on commit a2c43eb

Please sign in to comment.