use crate::sexpr::{self, Atom, Expr}; #[derive(Debug, Clone)] pub struct Rule { pub lhs: Expr, pub rhs: Expr } impl TryFrom for Rule { type Error = (); fn try_from(value: Expr) -> Result { if let Expr::Application(v) = value && v[0] == Expr::Atom(Atom::Builtin(String::from("def-rule"))) && v.len() == 3 { Ok(Rule { lhs: v[1].clone(), rhs: v[2].clone() }) } else {Err(())} } } pub fn parse_def_rules(input: String) -> Vec { let exprs = sexpr::Parser::new(&input).parse_all(); exprs.iter().filter_map(|e| e.clone().try_into().ok()).collect() }