From a2c43eba8ff0a1d7e081009e607989931c03504c Mon Sep 17 00:00:00 2001 From: Tobias Stolzmann Date: Wed, 20 Nov 2024 18:52:10 +0100 Subject: [PATCH] Implement a convenience method on fol::Comparison that returns the individual comparisons --- src/syntax_tree/fol.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/syntax_tree/fol.rs b/src/syntax_tree/fol.rs index c501ecbd..900b93b5 100644 --- a/src/syntax_tree/fol.rs +++ b/src/syntax_tree/fol.rs @@ -377,6 +377,36 @@ pub struct Comparison { impl_node!(Comparison, Format, ComparisonParser); impl Comparison { + pub fn individuals(&self) -> impl Iterator { + 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 { + 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());