1use oak_core::{ElementType, Token, TokenType, UniversalElementRole, UniversalTokenRole};
2use serde::{Deserialize, Serialize};
3
4pub type PascalToken = Token<PascalSyntaxKind>;
5
6#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
7pub enum PascalSyntaxKind {
8 Whitespace,
10 Newline,
11
12 Comment,
14
15 Program,
17 Begin,
18 End,
19 Var,
20 Const,
21 Type,
22 Function,
23 Procedure,
24 If,
25 Then,
26 Else,
27 While,
28 Do,
29 For,
30 To,
31 Downto,
32 Repeat,
33 Until,
34 Case,
35 Of,
36 With,
37 Record,
38 Array,
39 Set,
40 File,
41 Packed,
42 Nil,
43 True,
44 False,
45 And,
46 Or,
47 Not,
48 Div,
49 Mod,
50 In,
51
52 Identifier,
54 IntegerLiteral,
55 RealLiteral,
56 StringLiteral,
57 CharLiteral,
58
59 Plus, Minus, Multiply, Divide, Assign, Equal, NotEqual, Less, LessEqual, Greater, GreaterEqual, LeftParen, RightParen, LeftBracket, RightBracket, Semicolon, Comma, Dot, Colon, Range, Caret, Root,
86 ProgramBlock,
87 VarSection,
88 ConstSection,
89 TypeSection,
90 ProcedureDef,
91 FunctionDef,
92 CompoundStmt,
93 IfStmt,
94 WhileStmt,
95 ForStmt,
96 Expression,
97
98 Error,
100 Eof,
101}
102
103impl TokenType for PascalSyntaxKind {
104 const END_OF_STREAM: Self = Self::Eof;
105 type Role = UniversalTokenRole;
106
107 fn role(&self) -> Self::Role {
108 match self {
109 Self::Whitespace | Self::Newline => UniversalTokenRole::Whitespace,
110 Self::Comment => UniversalTokenRole::Comment,
111 Self::Eof => UniversalTokenRole::Eof,
112 _ => UniversalTokenRole::None,
113 }
114 }
115
116 fn is_comment(&self) -> bool {
117 matches!(self, Self::Comment)
118 }
119
120 fn is_whitespace(&self) -> bool {
121 matches!(self, Self::Whitespace | Self::Newline)
122 }
123}
124
125impl ElementType for PascalSyntaxKind {
126 type Role = UniversalElementRole;
127
128 fn role(&self) -> Self::Role {
129 match self {
130 Self::Error => UniversalElementRole::Error,
131 Self::Root => UniversalElementRole::Root,
132 Self::ProgramBlock | Self::ProcedureDef | Self::FunctionDef | Self::VarSection => UniversalElementRole::Detail,
133 _ => UniversalElementRole::None,
134 }
135 }
136}