1use oak_core::{ElementType, TokenType, UniversalElementRole, UniversalTokenRole};
2
3#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
4pub enum MatlabSyntaxKind {
5 Whitespace,
7 Newline,
8 Comment,
9 BlockComment,
10
11 Identifier,
13 Number,
14 String,
15 Character,
16
17 Function,
19 End,
20 If,
21 Else,
22 Elseif,
23 While,
24 For,
25 Break,
26 Continue,
27 Return,
28 Switch,
29 Case,
30 Otherwise,
31 Try,
32 Catch,
33 Global,
34 Persistent,
35 Classdef,
36 Properties,
37 Methods,
38 Events,
39
40 Plus, Minus, Times, Divide, Power, LeftDivide, DotTimes, DotDivide, DotPower, DotLeftDivide, Equal, NotEqual, Less, Greater, LessEqual, GreaterEqual, And, Or, Not, AndAnd, OrOr, Assign, LeftParen, RightParen, LeftBracket, RightBracket, LeftBrace, RightBrace, Semicolon, Comma, Dot, Colon, Question, At, Transpose, DotTranspose, Operator,
90 Delimiter,
91
92 Error,
94
95 Script,
97 FunctionDef,
98 ClassDef,
99 Block,
100 Expression,
101 Statement,
102
103 Eof,
105}
106
107impl MatlabSyntaxKind {
108 pub fn is_token(&self) -> bool {
109 !self.is_element()
110 }
111
112 pub fn is_element(&self) -> bool {
113 matches!(self, Self::Script | Self::FunctionDef | Self::ClassDef | Self::Block | Self::Expression | Self::Statement)
114 }
115}
116
117impl TokenType for MatlabSyntaxKind {
118 const END_OF_STREAM: Self = Self::Eof;
119 type Role = UniversalTokenRole;
120
121 fn role(&self) -> Self::Role {
122 match self {
123 Self::Whitespace | Self::Newline => UniversalTokenRole::Whitespace,
124 Self::Comment | Self::BlockComment => UniversalTokenRole::Comment,
125 Self::Eof => UniversalTokenRole::Eof,
126 _ => UniversalTokenRole::None,
127 }
128 }
129
130 fn is_comment(&self) -> bool {
131 matches!(self, Self::Comment | Self::BlockComment)
132 }
133
134 fn is_whitespace(&self) -> bool {
135 matches!(self, Self::Whitespace | Self::Newline)
136 }
137}
138
139impl ElementType for MatlabSyntaxKind {
140 type Role = UniversalElementRole;
141
142 fn role(&self) -> Self::Role {
143 match self {
144 Self::Error => UniversalElementRole::Error,
145 Self::Script => UniversalElementRole::Root,
146 Self::FunctionDef | Self::ClassDef => UniversalElementRole::Detail,
147 _ => UniversalElementRole::None,
148 }
149 }
150}