1use core::fmt;
2use oak_core::{SyntaxKind, Token};
3
4pub type RubyToken = Token<RubySyntaxKind>;
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize)]
9pub enum RubySyntaxKind {
10 Identifier,
12 IntegerLiteral,
13 FloatLiteral,
14 StringLiteral,
15 Symbol,
16 RegexLiteral,
17
18 If,
20 Unless,
21 Elsif,
22 Else,
23 Case,
24 When,
25 Then,
26 For,
27 While,
28 Until,
29 Break,
30 Next,
31 Redo,
32 Retry,
33 Return,
34 Yield,
35 Def,
36 Class,
37 Module,
38 End,
39 Lambda,
40 Proc,
41 Begin,
42 Rescue,
43 Ensure,
44 Raise,
45 Require,
46 Load,
47 Include,
48 Extend,
49 Prepend,
50 And,
51 Or,
52 Not,
53 In,
54 True,
55 False,
56 Nil,
57 Super,
58 Self_,
59 Alias,
60 Undef,
61 Defined,
62 Do,
63
64 Plus,
66 Minus,
67 Multiply,
68 Divide,
69 Modulo,
70 Power,
71 EqualEqual,
72 NotEqual,
73 Less,
74 Greater,
75 LessEqual,
76 GreaterEqual,
77 EqualEqualEqual,
78 Spaceship,
79 Assign,
80 PlusAssign,
81 MinusAssign,
82 MultiplyAssign,
83 DivideAssign,
84 ModuloAssign,
85 PowerAssign,
86 BitAnd,
87 BitOr,
88 Xor,
89 LogicalNot,
90 Tilde,
91 LeftShift,
92 RightShift,
93 AndAssign,
94 OrAssign,
95 XorAssign,
96 LeftShiftAssign,
97 RightShiftAssign,
98 AndAnd,
99 OrOr,
100 OrOrAssign,
101 AndAndAssign,
102 Question,
103 DotDot,
104 DotDotDot,
105 Match,
106 NotMatch,
107
108 LeftParen,
110 RightParen,
111 LeftBracket,
112 RightBracket,
113 LeftBrace,
114 RightBrace,
115 Comma,
116 Colon,
117 Semicolon,
118 Dot,
119 DoubleColon,
120 At,
121 Dollar,
122
123 Whitespace,
125 Newline,
126 Comment,
127
128 Eof,
130 Invalid,
131}
132
133impl fmt::Display for RubySyntaxKind {
134 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
135 let name = match self {
136 Self::Identifier => "Identifier",
137 Self::IntegerLiteral => "IntegerLiteral",
138 Self::FloatLiteral => "FloatLiteral",
139 Self::StringLiteral => "StringLiteral",
140 Self::Symbol => "Symbol",
141 Self::RegexLiteral => "RegexLiteral",
142
143 Self::If => "If",
144 Self::Unless => "Unless",
145 Self::Elsif => "Elsif",
146 Self::Else => "Else",
147 Self::Case => "Case",
148 Self::When => "When",
149 Self::Then => "Then",
150 Self::For => "For",
151 Self::While => "While",
152 Self::Until => "Until",
153 Self::Break => "Break",
154 Self::Next => "Next",
155 Self::Redo => "Redo",
156 Self::Retry => "Retry",
157 Self::Return => "Return",
158 Self::Yield => "Yield",
159 Self::Def => "Def",
160 Self::Class => "Class",
161 Self::Module => "Module",
162 Self::End => "End",
163 Self::Lambda => "Lambda",
164 Self::Proc => "Proc",
165 Self::Begin => "Begin",
166 Self::Rescue => "Rescue",
167 Self::Ensure => "Ensure",
168 Self::Raise => "Raise",
169 Self::Require => "Require",
170 Self::Load => "Load",
171 Self::Include => "Include",
172 Self::Extend => "Extend",
173 Self::Prepend => "Prepend",
174 Self::And => "And",
175 Self::Or => "Or",
176 Self::Not => "Not",
177 Self::In => "In",
178 Self::True => "True",
179 Self::False => "False",
180 Self::Nil => "Nil",
181 Self::Super => "Super",
182 Self::Self_ => "Self",
183 Self::Alias => "Alias",
184 Self::Undef => "Undef",
185 Self::Defined => "Defined",
186 Self::Do => "Do",
187
188 Self::Plus => "Plus",
189 Self::Minus => "Minus",
190 Self::Multiply => "Multiply",
191 Self::Divide => "Divide",
192 Self::Modulo => "Modulo",
193 Self::Power => "Power",
194 Self::EqualEqual => "EqualEqual",
195 Self::NotEqual => "NotEqual",
196 Self::Less => "Less",
197 Self::Greater => "Greater",
198 Self::LessEqual => "LessEqual",
199 Self::GreaterEqual => "GreaterEqual",
200 Self::EqualEqualEqual => "EqualEqualEqual",
201 Self::Spaceship => "Spaceship",
202 Self::Assign => "Assign",
203 Self::PlusAssign => "PlusAssign",
204 Self::MinusAssign => "MinusAssign",
205 Self::MultiplyAssign => "MultiplyAssign",
206 Self::DivideAssign => "DivideAssign",
207 Self::ModuloAssign => "ModuloAssign",
208 Self::PowerAssign => "PowerAssign",
209 Self::BitAnd => "BitAnd",
210 Self::BitOr => "BitOr",
211 Self::Xor => "Xor",
212 Self::LogicalNot => "LogicalNot",
213 Self::Tilde => "Tilde",
214 Self::LeftShift => "LeftShift",
215 Self::RightShift => "RightShift",
216 Self::AndAssign => "AndAssign",
217 Self::OrAssign => "OrAssign",
218 Self::XorAssign => "XorAssign",
219 Self::LeftShiftAssign => "LeftShiftAssign",
220 Self::RightShiftAssign => "RightShiftAssign",
221 Self::AndAnd => "AndAnd",
222 Self::OrOr => "OrOr",
223 Self::OrOrAssign => "OrOrAssign",
224 Self::AndAndAssign => "AndAndAssign",
225 Self::Question => "Question",
226 Self::DotDot => "DotDot",
227 Self::DotDotDot => "DotDotDot",
228 Self::Match => "Match",
229 Self::NotMatch => "NotMatch",
230
231 Self::LeftParen => "LeftParen",
232 Self::RightParen => "RightParen",
233 Self::LeftBracket => "LeftBracket",
234 Self::RightBracket => "RightBracket",
235 Self::LeftBrace => "LeftBrace",
236 Self::RightBrace => "RightBrace",
237 Self::Comma => "Comma",
238 Self::Colon => "Colon",
239 Self::Semicolon => "Semicolon",
240 Self::Dot => "Dot",
241 Self::DoubleColon => "DoubleColon",
242 Self::At => "At",
243 Self::Dollar => "Dollar",
244
245 Self::Whitespace => "Whitespace",
246 Self::Newline => "Newline",
247 Self::Comment => "Comment",
248 Self::Eof => "Eof",
249 Self::Invalid => "Invalid",
250 };
251 write!(f, "{}", name)
252 }
253}
254
255impl SyntaxKind for RubySyntaxKind {
256 fn is_trivia(&self) -> bool {
257 matches!(self, Self::Whitespace | Self::Newline)
258 }
259
260 fn is_comment(&self) -> bool {
261 matches!(self, Self::Comment)
262 }
263
264 fn is_whitespace(&self) -> bool {
265 matches!(self, Self::Whitespace | Self::Newline)
266 }
267
268 fn is_token_type(&self) -> bool {
269 true }
271
272 fn is_element_type(&self) -> bool {
273 false }
275}