Skip to main content

oak_prolog/lexer/
token_type.rs

1use oak_core::{Token, TokenType, UniversalTokenRole};
2
3/// Prolog token.
4pub type PrologToken = Token<PrologTokenType>;
5
6impl PrologTokenType {
7    /// Check if this type is a token.
8    pub fn is_token(&self) -> bool {
9        !self.is_element()
10    }
11
12    /// Check if this type is a structure element.
13    pub fn is_element(&self) -> bool {
14        matches!(self, Self::Root | Self::Functor | Self::Clause | Self::Rule | Self::Fact | Self::Query | Self::Directive | Self::List | Self::Structure)
15    }
16}
17
18impl TokenType for PrologTokenType {
19    type Role = UniversalTokenRole;
20    const END_OF_STREAM: Self = Self::Error;
21
22    fn is_ignored(&self) -> bool {
23        false
24    }
25
26    fn role(&self) -> Self::Role {
27        match self {
28            _ => UniversalTokenRole::None,
29        }
30    }
31}
32
33/// Prolog token types.
34#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
35#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
36pub enum PrologTokenType {
37    // Whitespace and comments
38    /// Whitespace.
39    Whitespace,
40    /// Newline.
41    Newline,
42    /// Comment.
43    Comment,
44
45    // Literals
46    /// Atom.
47    Atom,
48    /// Integer.
49    Integer,
50    /// Float.
51    Float,
52    /// String.
53    String,
54    /// Variable.
55    Variable,
56
57    // Operators
58    /// Unification `=`.
59    Unify, // =
60    /// Not unification `\=`.
61    NotUnify, // \=
62    /// Equal `==`.
63    Equal, // ==
64    /// Not equal `\==`.
65    NotEqual, // \==
66    /// Arithmetic equal `=:=`.
67    ArithEqual, // =:=
68    /// Arithmetic not equal `=\=`.
69    ArithNotEqual, // =\=
70    /// Less than `<`.
71    Less, // <
72    /// Greater than `>`.
73    Greater, // >
74    /// Less or equal `=<`.
75    LessEqual, // =<
76    /// Greater or equal `>=`.
77    GreaterEqual, // >=
78    /// Is `is`.
79    Is, // is
80    /// Plus `+`.
81    Plus, // +
82    /// Minus `-`.
83    Minus, // -
84    /// Multiply `*`.
85    Multiply, // *
86    /// Divide `/`.
87    Divide, // /
88    /// Integer divide `//`.
89    IntDivide, // //
90    /// Modulo `mod`.
91    Modulo, // mod
92    /// Power `**`.
93    Power, // **
94    /// Bitwise and `/\`.
95    BitwiseAnd, // /\
96    /// Bitwise or `\/`.
97    BitwiseOr, // \/
98    /// Bitwise xor `xor`.
99    BitwiseXor, // xor
100    /// Bitwise not `\`.
101    BitwiseNot, // \
102    /// Left shift `<<`.
103    LeftShift, // <<
104    /// Right shift `>>`.
105    RightShift, // >>
106
107    // Punctuation
108    /// Left parenthesis `(`.
109    LeftParen, // (
110    /// Right parenthesis `)`.
111    RightParen, // )
112    /// Left bracket `[`.
113    LeftBracket, // [
114    /// Right bracket `]`.
115    RightBracket, // ]
116    /// Left brace `{`.
117    LeftBrace, // {
118    /// Right brace `}`.
119    RightBrace, // }
120    /// Comma `,`.
121    Comma, // ,
122    /// Dot `.`.
123    Dot, // .
124    /// Pipe `|`.
125    Pipe, // |
126    /// Semicolon `;`.
127    Semicolon, // ;
128    /// Cut `!`.
129    Cut, // !
130    /// Question mark `?`.
131    Question, // ?
132    /// Colon `:`.
133    Colon, // :
134    /// Colon minus `:-`.
135    ColonMinus, // :-
136    /// Question minus `?-`.
137    QuestionMinus, // ?-
138
139    // Special constructs
140    /// Functor.
141    Functor,
142    /// Clause.
143    Clause,
144    /// Rule.
145    Rule,
146    /// Fact.
147    Fact,
148    /// Query.
149    Query,
150    /// Directive.
151    Directive,
152    /// List.
153    List,
154    /// Structure.
155    Structure,
156
157    // Special
158    /// Root.
159    Root,
160    /// Error.
161    Error,
162}