Skip to main content

kermit_parser/
join_query.rs

1/// A single term in a Datalog predicate.
2///
3/// Variables start with an uppercase letter (e.g. `X`, `Name`), atoms start
4/// with a lowercase letter (e.g. `alice`, `edge`), and `_` is the anonymous
5/// placeholder that matches anything without binding.
6#[derive(Debug, Clone, PartialEq, Eq)]
7pub enum Term {
8    /// A named variable (e.g. `X`).
9    Var(String),
10    /// A ground constant (e.g. `alice`).
11    Atom(String),
12    /// The anonymous wildcard `_`.
13    Placeholder,
14}
15
16/// A Datalog predicate application, e.g. `edge(X, Y)`.
17#[derive(Debug, Clone, PartialEq, Eq)]
18pub struct Predicate {
19    /// Predicate name (e.g. `"edge"`).
20    pub name: String,
21    /// Argument terms in order.
22    pub terms: Vec<Term>,
23}
24
25/// A parsed Datalog join query of the form `Head :- Body1, Body2, ... .`
26///
27/// For example: `path(X, Z) :- edge(X, Y), edge(Y, Z).`
28///
29/// Implements [`FromStr`](std::str::FromStr) for parsing from a string.
30#[derive(Debug, Clone, PartialEq, Eq)]
31pub struct JoinQuery {
32    /// The head predicate defining the output schema.
33    pub head: Predicate,
34    /// The body predicates to be joined.
35    pub body: Vec<Predicate>,
36}