1use oak_core::{ElementType, TokenType, UniversalElementRole, UniversalTokenRole};
2use serde::{Deserialize, Serialize};
3use std::fmt;
4
5#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
6pub enum WolframSyntaxKind {
7 Root,
8
9 Whitespace,
11 Newline,
12
13 Identifier,
15 Integer,
16 Real,
17 String,
18
19 If,
21 Then,
22 Else,
23 While,
24 For,
25 Do,
26 Function,
27 Module,
28 Block,
29 With,
30 Table,
31 Map,
32 Apply,
33 Select,
34 Cases,
35 Rule,
36 RuleDelayed,
37 Set,
38 SetDelayed,
39 Unset,
40 Clear,
41 ClearAll,
42 Return,
43 Break,
44 Continue,
45 True,
46 False,
47 Null,
48 Export,
49 Import,
50
51 Plus, Minus, Times, Divide, Power, Equal, NotEqual, Less, Greater, LessEqual, GreaterEqual, And, Or, Not, Assign, AddTo, SubtractFrom, TimesBy, DivideBy, LeftParen, RightParen, LeftBracket, RightBracket, LeftBrace, RightBrace, Comma, Semicolon, Colon, Dot, Arrow, DoubleArrow, Question, Underscore, DoubleUnderscore, TripleUnderscore, Slot, SlotSequence, Comment,
98
99 Text,
101
102 Error,
104
105 Eof,
107}
108
109impl fmt::Display for WolframSyntaxKind {
110 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
111 write!(f, "{:?}", self)
112 }
113}
114
115impl TokenType for WolframSyntaxKind {
116 const END_OF_STREAM: Self = WolframSyntaxKind::Eof;
117 type Role = UniversalTokenRole;
118
119 fn role(&self) -> Self::Role {
120 UniversalTokenRole::None
121 }
122
123 fn is_ignored(&self) -> bool {
124 matches!(self, WolframSyntaxKind::Whitespace | WolframSyntaxKind::Newline | WolframSyntaxKind::Comment)
125 }
126
127 fn is_comment(&self) -> bool {
128 matches!(self, WolframSyntaxKind::Comment)
129 }
130
131 fn is_whitespace(&self) -> bool {
132 matches!(self, WolframSyntaxKind::Whitespace | WolframSyntaxKind::Newline)
133 }
134}
135
136impl ElementType for WolframSyntaxKind {
137 type Role = UniversalElementRole;
138
139 fn role(&self) -> Self::Role {
140 match self {
141 WolframSyntaxKind::Error => UniversalElementRole::Error,
142 _ => UniversalElementRole::None,
143 }
144 }
145}