Skip to content

Commit

Permalink
Add helper function for getting Predicates in the ASP syntax tree
Browse files Browse the repository at this point in the history
  • Loading branch information
teiesti authored and ZachJHansen committed Dec 8, 2023
1 parent d2f130c commit 7a34a28
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/syntax_tree/asp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ pub struct Literal {
impl_node!(Literal, Format, LiteralParser);

impl Literal {
pub fn predicate(&self) -> Predicate {
self.atom.predicate()
}

pub fn variables(&self) -> HashSet<Variable> {
self.atom.variables()
}
Expand Down Expand Up @@ -178,6 +182,13 @@ impl AtomicFormula {
AtomicFormula::Comparison(c) => c.variables(),
}
}

pub fn predicates(&self) -> HashSet<Predicate> {
match &self {
AtomicFormula::Literal(l) => HashSet::from([l.predicate()]),
AtomicFormula::Comparison(_) => HashSet::new(),
}
}
}

#[derive(Clone, Debug, Eq, PartialEq, Hash)]
Expand All @@ -190,6 +201,8 @@ pub enum Head {
impl_node!(Head, Format, HeadParser);

impl Head {
// TODO: Revisit these helper function; make sure they are symmetric with all the others.

pub fn predicate(&self) -> Option<&str> {
match self {
Head::Basic(a) => Some(&a.predicate_symbol),
Expand Down

0 comments on commit 7a34a28

Please sign in to comment.