nova-interpreter 0.1.1

An interpreter library for the nova language
Documentation
#[derive(Debug, Clone)]
pub struct Rule {
    pub conditions: Box<[(usize, usize)]>,
    pub multiplicities: Box<[(usize, usize)]>,
}

impl Rule {
    pub fn is_fact(&self) -> bool {
        self.conditions.len() == 0
    }

    pub fn is_rule(&self) -> bool {
        !self.is_fact()
    }
}

#[derive(Debug, Clone)]
pub struct RuleSet {
    pub rules: Vec<Rule>,
    pub facts: Vec<Rule>,
}

#[derive(Debug, Clone)]
pub struct BakedRuleset {
    pub rules: Box<[Rule]>,
    pub facts: Box<[Rule]>,
}

impl From<RuleSet> for BakedRuleset {
    fn from(value: RuleSet) -> Self {
        BakedRuleset {
            rules: value.rules.into_boxed_slice(),
            facts: value.facts.into_boxed_slice(),
        }
    }
}

impl RuleSet {
    pub fn empty() -> RuleSet {
        RuleSet {
            rules: vec![],
            facts: vec![],
        }
    }
}

impl std::ops::AddAssign for RuleSet {
    fn add_assign(&mut self, mut rhs: Self) {
        self.rules.append(&mut rhs.rules);
        self.facts.append(&mut rhs.facts);
    }
}