30 lines
605 B
Plaintext
30 lines
605 B
Plaintext
use l0::ast::{Atom, Term, TopLevel, Var};
|
|
|
|
grammar;
|
|
|
|
pub TopLevel: TopLevel = {
|
|
"?-" <t:Term> "." => TopLevel::Query(t),
|
|
<t:Term> "." => TopLevel::Fact(t),
|
|
};
|
|
|
|
Atom : Atom = {
|
|
r"[a-z][a-z0-9_]*" => <>.trim().to_string(),
|
|
};
|
|
|
|
Var : Var = {
|
|
r"[A-Z][a-z0-9_]*" => <>.trim().to_string(),
|
|
};
|
|
|
|
BoxedTerm : Box<Term> = {
|
|
<t:Term> => Box::new(t),
|
|
};
|
|
|
|
Term : Term = {
|
|
<a:Atom> "(" <ts: (<BoxedTerm> ",")*> <t:BoxedTerm> ")" => {
|
|
let mut ts = ts;
|
|
ts.push(t);
|
|
Term::Clause(a, ts)
|
|
},
|
|
<Atom> => Term::Atom(<>),
|
|
<Var> => Term::Var(<>),
|
|
}; |