oak_prolog/parser/
element_type.rs1use oak_core::{ElementType, Parser, UniversalElementRole};
2#[cfg(feature = "serde")]
3use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
6#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7pub enum PrologElementType {
8 Whitespace,
10 Newline,
11 Comment,
12
13 Atom,
15 Integer,
16 Float,
17 String,
18 Variable,
19
20 Unify, NotUnify, Equal, NotEqual, ArithEqual, ArithNotEqual, Less, Greater, LessEqual, GreaterEqual, Is, Plus, Minus, Multiply, Divide, IntDivide, Modulo, Power, BitwiseAnd, BitwiseOr, BitwiseXor, BitwiseNot, LeftShift, RightShift, LeftParen, RightParen, LeftBracket, RightBracket, LeftBrace, RightBrace, Comma, Dot, Pipe, Semicolon, Cut, Question, Colon, ColonMinus, QuestionMinus, Functor,
65 Clause,
66 Rule,
67 Fact,
68 Query,
69 Directive,
70 List,
71 Structure,
72
73 Root,
75 Error,
76 Eof,
77}
78
79impl PrologElementType {
80 pub fn is_token(&self) -> bool {
81 !self.is_element()
82 }
83
84 pub fn is_element(&self) -> bool {
85 matches!(self, Self::Root | Self::Functor | Self::Clause | Self::Rule | Self::Fact | Self::Query | Self::Directive | Self::List | Self::Structure)
86 }
87}
88
89impl ElementType for PrologElementType {
90 type Role = UniversalElementRole;
91
92 fn role(&self) -> Self::Role {
93 match self {
94 _ => UniversalElementRole::None,
95 }
96 }
97}
98
99impl From<crate::lexer::token_type::PrologTokenType> for PrologElementType {
100 fn from(token: crate::lexer::token_type::PrologTokenType) -> Self {
101 unsafe { std::mem::transmute(token) }
102 }
103}