1use oak_core::{Token, TokenType, UniversalTokenRole};
2#[cfg(feature = "serde")]
3use serde::{Deserialize, Serialize};
4
5pub type TexToken = Token<TexTokenType>;
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
8#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9#[repr(u8)]
10pub enum TexTokenType {
11 Root,
13 SourceFile,
14 Document,
15
16 Command,
18 Environment,
19 BeginEnvironment,
20 EndEnvironment,
21
22 MathMode,
24 InlineMath,
25 DisplayMath,
26 Group,
27 Superscript,
28 Subscript,
29
30 Argument,
32 OptionalArgument,
33 MandatoryArgument,
34
35 Text,
37 Paragraph,
38 Section,
39 Subsection,
40 Subsubsection,
41
42 List,
44 Item,
45 Table,
46 Row,
47 Cell,
48
49 Label,
51 Reference,
52 Citation,
53
54 Figure,
56 Caption,
57
58 Error,
60
61 DocumentClass,
63 UsePackage,
64 Begin,
65 End,
66 Section_,
67 Subsection_,
68 Subsubsection_,
69 Chapter,
70 Part,
71 Title,
72 Author,
73 Date,
74 MakeTitle,
75 TableOfContents,
76 NewPage,
77 ClearPage,
78
79 Frac,
81 Sqrt,
82 Sum,
83 Int,
84 Lim,
85 Alpha,
86 Beta,
87 Gamma,
88 Delta,
89 Epsilon,
90 Zeta,
91 Eta,
92 Theta,
93 Iota,
94 Kappa,
95 Lambda,
96 Mu,
97 Nu,
98 Xi,
99 Omicron,
100 Pi,
101 Rho,
102 Sigma,
103 Tau,
104 Upsilon,
105 Phi,
106 Chi,
107 Psi,
108 Omega,
109 VarEpsilon,
110 VarTheta,
111 VarKappa,
112 VarPi,
113 VarRho,
114 VarSigma,
115 VarPhi,
116 UpperGamma,
117 UpperDelta,
118 UpperTheta,
119 UpperLambda,
120 UpperXi,
121 UpperPi,
122 UpperSigma,
123 UpperUpsilon,
124 UpperPhi,
125 UpperPsi,
126 UpperOmega,
127
128 TextBf,
130 TextIt,
131 TextSc,
132 TextTt,
133 Emph,
134 Underline,
135
136 Identifier,
138 StringLiteral,
139 Number,
140
141 Backslash,
143 LeftBrace,
144 RightBrace,
145 LeftBracket,
146 RightBracket,
147 LeftParen,
148 RightParen,
149 Dollar,
150 DoubleDollar,
151 Ampersand,
152 Percent,
153 Hash,
154 Caret,
155 Underscore,
156 Tilde,
157
158 Equal,
160 Equals,
161 Plus,
162 Minus,
163 Star,
164 Slash,
165 Pipe,
166 Less,
167 LessThan,
168 Greater,
169 GreaterThan,
170 Exclamation,
171 Question,
172 At,
173 Colon,
174 Semicolon,
175 Comma,
176 Dot,
177
178 Comment,
180 Whitespace,
181 Newline,
182
183 BeginKeyword,
185 EndKeyword,
186 DocumentclassKeyword,
187 UsepackageKeyword,
188 SectionKeyword,
189 SubsectionKeyword,
190 SubsubsectionKeyword,
191 ChapterKeyword,
192 PartKeyword,
193 TitleKeyword,
194 AuthorKeyword,
195 DateKeyword,
196 MaketitleKeyword,
197 TableofcontentsKeyword,
198 ItemKeyword,
199 LabelKeyword,
200 RefKeyword,
201 CiteKeyword,
202 IncludegraphicsKeyword,
203 TextbfKeyword,
204 TextitKeyword,
205 EmphKeyword,
206
207 Eof,
209}
210
211impl From<crate::parser::element_type::TexElementType> for TexTokenType {
212 fn from(element: crate::parser::element_type::TexElementType) -> Self {
213 use crate::parser::element_type::TexElementType as E;
214 match element {
215 E::Root => Self::Root,
216 E::SourceFile => Self::SourceFile,
217 E::Document => Self::Document,
218 E::Command => Self::Command,
219 E::Environment => Self::Environment,
220 E::BeginEnvironment => Self::BeginEnvironment,
221 E::EndEnvironment => Self::EndEnvironment,
222 E::MathMode => Self::MathMode,
223 E::InlineMath => Self::InlineMath,
224 E::DisplayMath => Self::DisplayMath,
225 E::Group => Self::Group,
226 E::Superscript => Self::Superscript,
227 E::Subscript => Self::Subscript,
228 E::Argument => Self::Argument,
229 E::OptionalArgument => Self::OptionalArgument,
230 E::MandatoryArgument => Self::MandatoryArgument,
231 E::Text => Self::Text,
232 E::Paragraph => Self::Paragraph,
233 E::Section => Self::Section,
234 E::Subsection => Self::Subsection,
235 E::Subsubsection => Self::Subsubsection,
236 E::List => Self::List,
237 E::Item => Self::Item,
238 E::Table => Self::Table,
239 E::Row => Self::Row,
240 E::Cell => Self::Cell,
241 E::Label => Self::Label,
242 E::Reference => Self::Reference,
243 E::Citation => Self::Citation,
244 E::Figure => Self::Figure,
245 E::Caption => Self::Caption,
246 E::Error => Self::Error,
247 E::DocumentClass => Self::DocumentClass,
248 E::UsePackage => Self::UsePackage,
249 E::Begin => Self::Begin,
250 E::End => Self::End,
251 E::Section_ => Self::Section_,
252 E::Subsection_ => Self::Subsection_,
253 E::Subsubsection_ => Self::Subsubsection_,
254 E::Chapter => Self::Chapter,
255 E::Part => Self::Part,
256 E::Title => Self::Title,
257 E::Author => Self::Author,
258 E::Date => Self::Date,
259 E::MakeTitle => Self::MakeTitle,
260 E::TableOfContents => Self::TableOfContents,
261 E::NewPage => Self::NewPage,
262 E::ClearPage => Self::ClearPage,
263 E::Frac => Self::Frac,
264 E::Sqrt => Self::Sqrt,
265 E::Sum => Self::Sum,
266 E::Int => Self::Int,
267 E::Lim => Self::Lim,
268 E::Alpha => Self::Alpha,
269 E::Beta => Self::Beta,
270 E::Gamma => Self::Gamma,
271 E::Delta => Self::Delta,
272 E::Epsilon => Self::Epsilon,
273 E::Zeta => Self::Zeta,
274 E::Eta => Self::Eta,
275 E::Theta => Self::Theta,
276 E::Iota => Self::Iota,
277 E::Kappa => Self::Kappa,
278 E::Lambda => Self::Lambda,
279 E::Mu => Self::Mu,
280 E::Nu => Self::Nu,
281 E::Xi => Self::Xi,
282 E::Omicron => Self::Omicron,
283 E::Pi => Self::Pi,
284 E::Rho => Self::Rho,
285 E::Sigma => Self::Sigma,
286 E::Tau => Self::Tau,
287 E::Upsilon => Self::Upsilon,
288 E::Phi => Self::Phi,
289 E::Chi => Self::Chi,
290 E::Psi => Self::Psi,
291 E::Omega => Self::Omega,
292 E::VarEpsilon => Self::VarEpsilon,
293 E::VarTheta => Self::VarTheta,
294 E::VarKappa => Self::VarKappa,
295 E::VarPi => Self::VarPi,
296 E::VarRho => Self::VarRho,
297 E::VarSigma => Self::VarSigma,
298 E::VarPhi => Self::VarPhi,
299 E::UpperGamma => Self::UpperGamma,
300 E::UpperDelta => Self::UpperDelta,
301 E::UpperTheta => Self::UpperTheta,
302 E::UpperLambda => Self::UpperLambda,
303 E::UpperXi => Self::UpperXi,
304 E::UpperPi => Self::UpperPi,
305 E::UpperSigma => Self::UpperSigma,
306 E::UpperUpsilon => Self::UpperUpsilon,
307 E::UpperPhi => Self::UpperPhi,
308 E::UpperPsi => Self::UpperPsi,
309 E::UpperOmega => Self::UpperOmega,
310 E::TextBf => Self::TextBf,
311 E::TextIt => Self::TextIt,
312 E::TextSc => Self::TextSc,
313 E::TextTt => Self::TextTt,
314 E::Emph => Self::Emph,
315 E::Underline => Self::Underline,
316 E::Identifier => Self::Identifier,
317 E::StringLiteral => Self::StringLiteral,
318 E::Number => Self::Number,
319 E::Backslash => Self::Backslash,
320 E::LeftBrace => Self::LeftBrace,
321 E::RightBrace => Self::RightBrace,
322 E::LeftBracket => Self::LeftBracket,
323 E::RightBracket => Self::RightBracket,
324 E::LeftParen => Self::LeftParen,
325 E::RightParen => Self::RightParen,
326 E::Dollar => Self::Dollar,
327 E::DoubleDollar => Self::DoubleDollar,
328 E::Ampersand => Self::Ampersand,
329 E::Percent => Self::Percent,
330 E::Hash => Self::Hash,
331 E::Caret => Self::Caret,
332 E::Underscore => Self::Underscore,
333 E::Tilde => Self::Tilde,
334 E::Equal => Self::Equal,
335 E::Equals => Self::Equals,
336 E::Plus => Self::Plus,
337 E::Minus => Self::Minus,
338 E::Star => Self::Star,
339 E::Slash => Self::Slash,
340 E::Pipe => Self::Pipe,
341 E::Less => Self::Less,
342 E::LessThan => Self::LessThan,
343 E::Greater => Self::Greater,
344 E::GreaterThan => Self::GreaterThan,
345 E::Exclamation => Self::Exclamation,
346 E::Question => Self::Question,
347 E::At => Self::At,
348 E::Colon => Self::Colon,
349 E::Semicolon => Self::Semicolon,
350 E::Comma => Self::Comma,
351 E::Dot => Self::Dot,
352 E::Comment => Self::Comment,
353 E::Whitespace => Self::Whitespace,
354 E::Newline => Self::Newline,
355 E::BeginKeyword => Self::BeginKeyword,
356 E::EndKeyword => Self::EndKeyword,
357 E::DocumentclassKeyword => Self::DocumentclassKeyword,
358 E::UsepackageKeyword => Self::UsepackageKeyword,
359 E::SectionKeyword => Self::SectionKeyword,
360 E::SubsectionKeyword => Self::SubsectionKeyword,
361 E::SubsubsectionKeyword => Self::SubsubsectionKeyword,
362 E::ChapterKeyword => Self::ChapterKeyword,
363 E::PartKeyword => Self::PartKeyword,
364 E::TitleKeyword => Self::TitleKeyword,
365 E::AuthorKeyword => Self::AuthorKeyword,
366 E::DateKeyword => Self::DateKeyword,
367 E::MaketitleKeyword => Self::MaketitleKeyword,
368 E::TableofcontentsKeyword => Self::TableofcontentsKeyword,
369 E::ItemKeyword => Self::ItemKeyword,
370 E::LabelKeyword => Self::LabelKeyword,
371 E::RefKeyword => Self::RefKeyword,
372 E::CiteKeyword => Self::CiteKeyword,
373 E::IncludegraphicsKeyword => Self::IncludegraphicsKeyword,
374 E::TextbfKeyword => Self::TextbfKeyword,
375 E::TextitKeyword => Self::TextitKeyword,
376 E::EmphKeyword => Self::EmphKeyword,
377 E::Eof => Self::Eof,
378 }
379 }
380}
381
382impl TokenType for TexTokenType {
383 type Role = UniversalTokenRole;
384 const END_OF_STREAM: Self = Self::Eof;
385
386 fn is_ignored(&self) -> bool {
387 matches!(self, Self::Whitespace | Self::Newline | Self::Comment)
388 }
389
390 fn role(&self) -> Self::Role {
391 match self {
392 Self::Whitespace | Self::Newline => UniversalTokenRole::Whitespace,
393 Self::Comment => UniversalTokenRole::Comment,
394 Self::Eof => UniversalTokenRole::Eof,
395 Self::Error => UniversalTokenRole::Error,
396 _ => UniversalTokenRole::None,
397 }
398 }
399}