Skip to main content

oak_prolog/ast/
mod.rs

1#![doc = include_str!("readme.md")]
2
3/// Prolog root node.
4#[derive(Debug, Clone)]
5pub struct PrologRoot;
6
7/// Prolog token type alias.
8pub type PrologToken = crate::lexer::PrologTokenType;
9
10/// Prolog source file.
11#[derive(Debug, Clone)]
12pub struct SourceFile {
13    /// All clauses in the file.
14    pub clauses: Vec<Clause>,
15}
16
17/// Prolog clause.
18#[derive(Debug, Clone)]
19pub enum Clause {
20    /// Rule.
21    Rule(Rule),
22    /// Fact.
23    Fact(Fact),
24    /// Query.
25    Query(Query),
26    /// Directive.
27    Directive(Directive),
28}
29
30/// Prolog rule.
31#[derive(Debug, Clone)]
32pub struct Rule {
33    /// Rule head.
34    pub head: Term,
35    /// Rule body.
36    pub body: Term,
37}
38
39/// Prolog fact.
40#[derive(Debug, Clone)]
41pub struct Fact {
42    /// Fact term.
43    pub term: Term,
44}
45
46/// Prolog query.
47#[derive(Debug, Clone)]
48pub struct Query {
49    /// Query term.
50    pub term: Term,
51}
52
53/// Prolog directive.
54#[derive(Debug, Clone)]
55pub struct Directive {
56    /// Directive term.
57    pub term: Term,
58}
59
60/// Prolog term.
61#[derive(Debug, Clone)]
62pub enum Term {
63    /// Atom.
64    Atom(String),
65    /// Variable.
66    Variable(String),
67    /// Number.
68    Number(String),
69    /// String.
70    String(String),
71    /// Compound term.
72    Compound {
73        /// Functor.
74        functor: String,
75        /// Arguments list.
76        args: Vec<Term>,
77    },
78    /// List.
79    List(Vec<Term>),
80}