1use oak_core::{ElementType, UniversalElementRole};
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
6#[repr(u8)]
7pub enum TexElementType {
8 Root,
10 SourceFile,
12 Document,
14
15 Command,
17 Environment,
19 BeginEnvironment,
21 EndEnvironment,
23
24 MathMode,
26 InlineMath,
28 DisplayMath,
30 Group,
32 Superscript,
34 Subscript,
36
37 Argument,
39 OptionalArgument,
41 MandatoryArgument,
43
44 Text,
46 Paragraph,
48 Section,
50 Subsection,
52 Subsubsection,
54
55 List,
57 Item,
59 Table,
61 Row,
63 Cell,
65
66 Label,
68 Reference,
70 Citation,
72
73 Figure,
75 Caption,
77
78 Error,
80
81 DocumentClass,
83 UsePackage,
85 Begin,
87 End,
89 Section_,
91 Subsection_,
93 Subsubsection_,
95 Chapter,
97 Part,
99 Title,
101 Author,
103 Date,
105 MakeTitle,
107 TableOfContents,
109 NewPage,
111 ClearPage,
113
114 Frac,
116 Sqrt,
118 Sum,
120 Int,
122 Lim,
124 Alpha,
126 Beta,
128 Gamma,
130 Delta,
132 Epsilon,
134 Zeta,
136 Eta,
138 Theta,
140 Iota,
142 Kappa,
144 Lambda,
146 Mu,
148 Nu,
150 Xi,
152 Omicron,
154 Pi,
156 Rho,
158 Sigma,
160 Tau,
162 Upsilon,
164 Phi,
166 Chi,
168 Psi,
170 Omega,
172 VarEpsilon,
174 VarTheta,
176 VarKappa,
178 VarPi,
180 VarRho,
182 VarSigma,
184 VarPhi,
186 UpperGamma,
188 UpperDelta,
190 UpperTheta,
192 UpperLambda,
194 UpperXi,
196 UpperPi,
198 UpperSigma,
200 UpperUpsilon,
202 UpperPhi,
204 UpperPsi,
206 UpperOmega,
208
209 TextBf,
211 TextIt,
213 TextSc,
215 TextTt,
217 Emph,
219 Underline,
221
222 Identifier,
224 StringLiteral,
226 Number,
228
229 Backslash,
231 LeftBrace,
233 RightBrace,
235 LeftBracket,
237 RightBracket,
239 LeftParen,
241 RightParen,
243 Dollar,
245 DoubleDollar,
247 Ampersand,
249 Percent,
251 Hash,
253 Caret,
255 Underscore,
257 Tilde,
259
260 Equal,
262 Equals,
264 Plus,
266 Minus,
268 Star,
270 Slash,
272 Pipe,
274 Less,
276 LessThan,
278 Greater,
280 GreaterThan,
282 Exclamation,
284 Question,
286 At,
288 Colon,
290 Semicolon,
292 Comma,
294 Dot,
296
297 Comment,
299 Whitespace,
301 Newline,
303
304 BeginKeyword,
306 EndKeyword,
308 DocumentclassKeyword,
310 UsepackageKeyword,
312 SectionKeyword,
314 SubsectionKeyword,
316 SubsubsectionKeyword,
318 ChapterKeyword,
320 PartKeyword,
322 TitleKeyword,
324 AuthorKeyword,
326 DateKeyword,
328 MaketitleKeyword,
330 TableofcontentsKeyword,
332 ItemKeyword,
334 LabelKeyword,
336 RefKeyword,
338 CiteKeyword,
340 IncludegraphicsKeyword,
342 TextbfKeyword,
344 TextitKeyword,
346 EmphKeyword,
348
349 Eof,
351}
352
353impl ElementType for TexElementType {
354 type Role = UniversalElementRole;
355
356 fn role(&self) -> Self::Role {
357 match self {
358 _ => UniversalElementRole::None,
359 }
360 }
361}
362
363impl oak_core::language::TokenType for TexElementType {
364 type Role = oak_core::UniversalTokenRole;
365 const END_OF_STREAM: Self = Self::Eof;
366
367 fn is_ignored(&self) -> bool {
368 matches!(self, Self::Whitespace | Self::Newline | Self::Comment)
369 }
370
371 fn role(&self) -> Self::Role {
372 match self {
373 Self::Whitespace | Self::Newline => oak_core::UniversalTokenRole::Whitespace,
374 Self::Comment => oak_core::UniversalTokenRole::Comment,
375 Self::Eof => oak_core::UniversalTokenRole::Eof,
376 Self::Error => oak_core::UniversalTokenRole::Error,
377 _ => oak_core::UniversalTokenRole::None,
378 }
379 }
380}
381
382impl From<crate::lexer::token_type::TexTokenType> for TexElementType {
383 fn from(token: crate::lexer::token_type::TexTokenType) -> Self {
384 use crate::lexer::token_type::TexTokenType as T;
385 match token {
386 T::Root => Self::Root,
387 T::SourceFile => Self::SourceFile,
388 T::Document => Self::Document,
389 T::Command => Self::Command,
390 T::Environment => Self::Environment,
391 T::BeginEnvironment => Self::BeginEnvironment,
392 T::EndEnvironment => Self::EndEnvironment,
393 T::MathMode => Self::MathMode,
394 T::InlineMath => Self::InlineMath,
395 T::DisplayMath => Self::DisplayMath,
396 T::Group => Self::Group,
397 T::Superscript => Self::Superscript,
398 T::Subscript => Self::Subscript,
399 T::Argument => Self::Argument,
400 T::OptionalArgument => Self::OptionalArgument,
401 T::MandatoryArgument => Self::MandatoryArgument,
402 T::Text => Self::Text,
403 T::Paragraph => Self::Paragraph,
404 T::Section => Self::Section,
405 T::Subsection => Self::Subsection,
406 T::Subsubsection => Self::Subsubsection,
407 T::List => Self::List,
408 T::Item => Self::Item,
409 T::Table => Self::Table,
410 T::Row => Self::Row,
411 T::Cell => Self::Cell,
412 T::Label => Self::Label,
413 T::Reference => Self::Reference,
414 T::Citation => Self::Citation,
415 T::Figure => Self::Figure,
416 T::Caption => Self::Caption,
417 T::Error => Self::Error,
418 T::DocumentClass => Self::DocumentClass,
419 T::UsePackage => Self::UsePackage,
420 T::Begin => Self::Begin,
421 T::End => Self::End,
422 T::Section_ => Self::Section_,
423 T::Subsection_ => Self::Subsection_,
424 T::Subsubsection_ => Self::Subsubsection_,
425 T::Chapter => Self::Chapter,
426 T::Part => Self::Part,
427 T::Title => Self::Title,
428 T::Author => Self::Author,
429 T::Date => Self::Date,
430 T::MakeTitle => Self::MakeTitle,
431 T::TableOfContents => Self::TableOfContents,
432 T::NewPage => Self::NewPage,
433 T::ClearPage => Self::ClearPage,
434 T::Frac => Self::Frac,
435 T::Sqrt => Self::Sqrt,
436 T::Sum => Self::Sum,
437 T::Int => Self::Int,
438 T::Lim => Self::Lim,
439 T::Alpha => Self::Alpha,
440 T::Beta => Self::Beta,
441 T::Gamma => Self::Gamma,
442 T::Delta => Self::Delta,
443 T::Epsilon => Self::Epsilon,
444 T::Zeta => Self::Zeta,
445 T::Eta => Self::Eta,
446 T::Theta => Self::Theta,
447 T::Iota => Self::Iota,
448 T::Kappa => Self::Kappa,
449 T::Lambda => Self::Lambda,
450 T::Mu => Self::Mu,
451 T::Nu => Self::Nu,
452 T::Xi => Self::Xi,
453 T::Omicron => Self::Omicron,
454 T::Pi => Self::Pi,
455 T::Rho => Self::Rho,
456 T::Sigma => Self::Sigma,
457 T::Tau => Self::Tau,
458 T::Upsilon => Self::Upsilon,
459 T::Phi => Self::Phi,
460 T::Chi => Self::Chi,
461 T::Psi => Self::Psi,
462 T::Omega => Self::Omega,
463 T::VarEpsilon => Self::VarEpsilon,
464 T::VarTheta => Self::VarTheta,
465 T::VarKappa => Self::VarKappa,
466 T::VarPi => Self::VarPi,
467 T::VarRho => Self::VarRho,
468 T::VarSigma => Self::VarSigma,
469 T::VarPhi => Self::VarPhi,
470 T::UpperGamma => Self::UpperGamma,
471 T::UpperDelta => Self::UpperDelta,
472 T::UpperTheta => Self::UpperTheta,
473 T::UpperLambda => Self::UpperLambda,
474 T::UpperXi => Self::UpperXi,
475 T::UpperPi => Self::UpperPi,
476 T::UpperSigma => Self::UpperSigma,
477 T::UpperUpsilon => Self::UpperUpsilon,
478 T::UpperPhi => Self::UpperPhi,
479 T::UpperPsi => Self::UpperPsi,
480 T::UpperOmega => Self::UpperOmega,
481 T::TextBf => Self::TextBf,
482 T::TextIt => Self::TextIt,
483 T::TextSc => Self::TextSc,
484 T::TextTt => Self::TextTt,
485 T::Emph => Self::Emph,
486 T::Underline => Self::Underline,
487 T::Identifier => Self::Identifier,
488 T::StringLiteral => Self::StringLiteral,
489 T::Number => Self::Number,
490 T::Backslash => Self::Backslash,
491 T::LeftBrace => Self::LeftBrace,
492 T::RightBrace => Self::RightBrace,
493 T::LeftBracket => Self::LeftBracket,
494 T::RightBracket => Self::RightBracket,
495 T::LeftParen => Self::LeftParen,
496 T::RightParen => Self::RightParen,
497 T::Dollar => Self::Dollar,
498 T::DoubleDollar => Self::DoubleDollar,
499 T::Ampersand => Self::Ampersand,
500 T::Percent => Self::Percent,
501 T::Hash => Self::Hash,
502 T::Caret => Self::Caret,
503 T::Underscore => Self::Underscore,
504 T::Tilde => Self::Tilde,
505 T::Equal => Self::Equal,
506 T::Equals => Self::Equals,
507 T::Plus => Self::Plus,
508 T::Minus => Self::Minus,
509 T::Star => Self::Star,
510 T::Slash => Self::Slash,
511 T::Pipe => Self::Pipe,
512 T::Less => Self::Less,
513 T::LessThan => Self::LessThan,
514 T::Greater => Self::Greater,
515 T::GreaterThan => Self::GreaterThan,
516 T::Exclamation => Self::Exclamation,
517 T::Question => Self::Question,
518 T::At => Self::At,
519 T::Colon => Self::Colon,
520 T::Semicolon => Self::Semicolon,
521 T::Comma => Self::Comma,
522 T::Dot => Self::Dot,
523 T::Comment => Self::Comment,
524 T::Whitespace => Self::Whitespace,
525 T::Newline => Self::Newline,
526 T::BeginKeyword => Self::BeginKeyword,
527 T::EndKeyword => Self::EndKeyword,
528 T::DocumentclassKeyword => Self::DocumentclassKeyword,
529 T::UsepackageKeyword => Self::UsepackageKeyword,
530 T::SectionKeyword => Self::SectionKeyword,
531 T::SubsectionKeyword => Self::SubsectionKeyword,
532 T::SubsubsectionKeyword => Self::SubsubsectionKeyword,
533 T::ChapterKeyword => Self::ChapterKeyword,
534 T::PartKeyword => Self::PartKeyword,
535 T::TitleKeyword => Self::TitleKeyword,
536 T::AuthorKeyword => Self::AuthorKeyword,
537 T::DateKeyword => Self::DateKeyword,
538 T::MaketitleKeyword => Self::MaketitleKeyword,
539 T::TableofcontentsKeyword => Self::TableofcontentsKeyword,
540 T::ItemKeyword => Self::ItemKeyword,
541 T::LabelKeyword => Self::LabelKeyword,
542 T::RefKeyword => Self::RefKeyword,
543 T::CiteKeyword => Self::CiteKeyword,
544 T::IncludegraphicsKeyword => Self::IncludegraphicsKeyword,
545 T::TextbfKeyword => Self::TextbfKeyword,
546 T::TextitKeyword => Self::TextitKeyword,
547 T::EmphKeyword => Self::EmphKeyword,
548 T::Eof => Self::Eof,
549 }
550 }
551}