1use oak_core::{Source, Token, TokenType, UniversalElementRole, UniversalTokenRole};
2#[cfg(feature = "serde")]
3use serde::{Deserialize, Serialize};
4
5pub type MatlabToken = Token<MatlabTokenType>;
6
7impl MatlabTokenType {
8 pub fn is_token(&self) -> bool {
9 !self.is_element()
10 }
11
12 pub fn is_element(&self) -> bool {
13 matches!(self, Self::Script | Self::FunctionDef | Self::ClassDef | Self::Block | Self::Expression | Self::Statement)
14 }
15}
16
17impl TokenType for MatlabTokenType {
18 type Role = UniversalTokenRole;
19 const END_OF_STREAM: Self = Self::Error;
20
21 fn is_ignored(&self) -> bool {
22 false
23 }
24
25 fn role(&self) -> Self::Role {
26 match self {
27 _ => UniversalTokenRole::None,
28 }
29 }
30}
31
32#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
33#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
34#[repr(u8)]
35pub enum MatlabTokenType {
36 Whitespace,
38 Newline,
39 Comment,
40 BlockComment,
41
42 Identifier,
44 Number,
45 String,
46 Character,
47
48 Function,
50 End,
51 If,
52 Else,
53 Elseif,
54 While,
55 For,
56 Break,
57 Continue,
58 Return,
59 Switch,
60 Case,
61 Otherwise,
62 Try,
63 Catch,
64 Global,
65 Persistent,
66 Classdef,
67 Properties,
68 Methods,
69 Events,
70
71 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,
121 Delimiter,
122
123 Error,
125
126 Script,
128 FunctionDef,
129 ClassDef,
130 Block,
131 Expression,
132 Statement,
133
134 Eof,
136}