use l3::ast::*; use std::cell::Cell; grammar; pub TopLevel: TopLevel = { "?-" "." => TopLevel::Query(t), => TopLevel::Predicate(<>), "." => TopLevel::Rule(<>), "." => TopLevel::Fact(<>) }; Atom : Atom = { r"[a-z][a-z0-9_]*" => <>.trim().to_string(), }; BoxedTerm : Box = { => Box::new(t) }; Clause : Term = { "(" ",")*> ")" => { let mut ts = ts; ts.push(t); Term::Clause(Cell::new(RegType::Temp(0)), a, ts) } }; Predicate : Vec = { )+> => { let mut pcs = pcs; pcs.push(pc); pcs } }; PredicateClause : PredicateClause = { "." => PredicateClause::Rule(<>), "." => PredicateClause::Fact(<>) }; Rule : Rule = { ":-" )*> => Rule { head: (c, h), clauses: cs }, ":-" )*> => Rule { head: (Term::Atom(Cell::new(RegType::Temp(0)), a), h), clauses: cs } }; Term : Term = { => <>, => Term::Atom(Cell::new(RegType::Temp(0)), <>), => Term::Var(Cell::new(VarReg::Norm(RegType::Temp(0))), <>) }; Var : Var = { r"[A-Z][a-z0-9_]*" => <>.trim().to_string(), };