scryer-prolog 0.8.59

A modern Prolog implementation written mostly in Rust.
use std::cell::{Cell};
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(Cell::new(0), a, ts)
     },
     <Atom> => Term::Atom(Cell::new(0), <>),
     <Var>  => Term::Var(Cell::new(0), <>),
};