Skip to content

Commit

Permalink
Add helper methods to Head
Browse files Browse the repository at this point in the history
  • Loading branch information
teiesti committed Nov 14, 2023
1 parent 9b2caaa commit fb4dd1d
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/syntax_tree/asp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,30 @@ pub enum Head {
impl_node!(Head, Format, HeadParser);

impl Head {
pub fn predicate(&self) -> Option<&str> {
match self {
Head::Basic(a) => Some(&a.predicate),
Head::Choice(a) => Some(&a.predicate),
Head::Falsity => None,
}
}

pub fn terms(&self) -> Option<&[Term]> {
match self {
Head::Basic(a) => Some(&a.terms),
Head::Choice(a) => Some(&a.terms),
Head::Falsity => None,
}
}

pub fn arity(&self) -> usize {
match self {
Head::Basic(a) => a.terms.len(),
Head::Choice(a) => a.terms.len(),
Head::Falsity => 0,
}
}

pub fn variables(&self) -> HashSet<Variable> {
match &self {
Head::Basic(a) | Head::Choice(a) => a.variables(),
Expand Down

0 comments on commit fb4dd1d

Please sign in to comment.