1use oak_core::{Token, TokenType, UniversalTokenRole};
2
3pub type TexToken = Token<TexTokenType>;
5
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
8#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
9#[repr(u8)]
10pub enum TexTokenType {
11 Root,
13 SourceFile,
15 Document,
17
18 Command,
20 Environment,
22 BeginEnvironment,
24 EndEnvironment,
26
27 MathMode,
29 InlineMath,
31 DisplayMath,
33 Group,
35 Superscript,
37 Subscript,
39
40 Argument,
42 OptionalArgument,
44 MandatoryArgument,
46
47 Text,
49 Paragraph,
51 Section,
53 Subsection,
55 Subsubsection,
57
58 List,
60 Item,
62 Table,
64 Row,
66 Cell,
68
69 Label,
71 Reference,
73 Citation,
75
76 Figure,
78 Caption,
80
81 Error,
83
84 DocumentClass,
86 UsePackage,
88 Begin,
90 End,
92 Section_,
94 Subsection_,
96 Subsubsection_,
98 Chapter,
100 Part,
102 Title,
104 Author,
106 Date,
108 MakeTitle,
110 TableOfContents,
112 NewPage,
114 ClearPage,
116
117 Frac,
119 Sqrt,
121 Sum,
123 Int,
125 Lim,
127 Alpha,
129 Beta,
131 Gamma,
133 Delta,
135 Epsilon,
137 Zeta,
139 Eta,
141 Theta,
143 Iota,
145 Kappa,
147 Lambda,
149 Mu,
151 Nu,
153 Xi,
155 Omicron,
157 Pi,
159 Rho,
161 Sigma,
163 Tau,
165 Upsilon,
167 Phi,
169 Chi,
171 Psi,
173 Omega,
175 VarEpsilon,
177 VarTheta,
179 VarKappa,
181 VarPi,
183 VarRho,
185 VarSigma,
187 VarPhi,
189 UpperGamma,
191 UpperDelta,
193 UpperTheta,
195 UpperLambda,
197 UpperXi,
199 UpperPi,
201 UpperSigma,
203 UpperUpsilon,
205 UpperPhi,
207 UpperPsi,
209 UpperOmega,
211
212 TextBf,
214 TextIt,
216 TextSc,
218 TextTt,
220 Emph,
222 Underline,
224
225 Identifier,
227 StringLiteral,
229 Number,
231
232 Backslash,
234 LeftBrace,
236 RightBrace,
238 LeftBracket,
240 RightBracket,
242 LeftParen,
244 RightParen,
246 Dollar,
248 DoubleDollar,
250 Ampersand,
252 Percent,
254 Hash,
256 Caret,
258 Underscore,
260 Tilde,
262
263 Equal,
265 Equals,
267 Plus,
269 Minus,
271 Star,
273 Slash,
275 Pipe,
277 Less,
279 LessThan,
281 Greater,
283 GreaterThan,
285 Exclamation,
287 Question,
289 At,
291 Colon,
293 Semicolon,
295 Comma,
297 Dot,
299
300 Comment,
302 Whitespace,
304 Newline,
306
307 BeginKeyword,
309 EndKeyword,
311 DocumentclassKeyword,
313 UsepackageKeyword,
315 SectionKeyword,
317 SubsectionKeyword,
319 SubsubsectionKeyword,
321 ChapterKeyword,
323 PartKeyword,
325 TitleKeyword,
327 AuthorKeyword,
329 DateKeyword,
331 MaketitleKeyword,
333 TableofcontentsKeyword,
335 ItemKeyword,
337 LabelKeyword,
339 RefKeyword,
341 CiteKeyword,
343 IncludegraphicsKeyword,
345 TextbfKeyword,
347 TextitKeyword,
349 EmphKeyword,
351
352 Eof,
354}
355
356impl TokenType for TexTokenType {
357 type Role = UniversalTokenRole;
358 const END_OF_STREAM: Self = Self::Eof;
359
360 fn is_ignored(&self) -> bool {
361 matches!(self, Self::Whitespace | Self::Newline | Self::Comment)
362 }
363
364 fn role(&self) -> Self::Role {
365 match self {
366 Self::Whitespace | Self::Newline => UniversalTokenRole::Whitespace,
367 Self::Comment => UniversalTokenRole::Comment,
368 Self::BeginKeyword
369 | Self::EndKeyword
370 | Self::DocumentclassKeyword
371 | Self::UsepackageKeyword
372 | Self::SectionKeyword
373 | Self::SubsectionKeyword
374 | Self::SubsubsectionKeyword
375 | Self::ChapterKeyword
376 | Self::PartKeyword
377 | Self::TitleKeyword
378 | Self::AuthorKeyword
379 | Self::DateKeyword
380 | Self::MaketitleKeyword
381 | Self::TableofcontentsKeyword
382 | Self::ItemKeyword
383 | Self::LabelKeyword
384 | Self::RefKeyword
385 | Self::CiteKeyword
386 | Self::IncludegraphicsKeyword
387 | Self::TextbfKeyword
388 | Self::TextitKeyword
389 | Self::EmphKeyword => UniversalTokenRole::Keyword,
390 Self::Number | Self::StringLiteral => UniversalTokenRole::Literal,
391 Self::Backslash
392 | Self::Plus
393 | Self::Minus
394 | Self::Star
395 | Self::Slash
396 | Self::Pipe
397 | Self::Less
398 | Self::LessThan
399 | Self::Greater
400 | Self::GreaterThan
401 | Self::Equal
402 | Self::Equals
403 | Self::Caret
404 | Self::Underscore
405 | Self::Tilde
406 | Self::Dollar
407 | Self::DoubleDollar
408 | Self::Ampersand
409 | Self::Hash
410 | Self::At => UniversalTokenRole::Operator,
411 Self::LeftBrace | Self::RightBrace | Self::LeftBracket | Self::RightBracket | Self::LeftParen | Self::RightParen | Self::Comma | Self::Dot | Self::Colon | Self::Semicolon | Self::Exclamation | Self::Question | Self::Percent => {
412 UniversalTokenRole::Punctuation
413 }
414 Self::Identifier | Self::Text => UniversalTokenRole::Name,
415 Self::Eof => UniversalTokenRole::Eof,
416 Self::Error => UniversalTokenRole::Error,
417 _ => UniversalTokenRole::None,
418 }
419 }
420}
421
422impl From<crate::parser::element_type::TexElementType> for TexTokenType {
423 fn from(element: crate::parser::element_type::TexElementType) -> Self {
424 use crate::parser::element_type::TexElementType as E;
425 match element {
426 E::Root => Self::Root,
427 E::SourceFile => Self::SourceFile,
428 E::Document => Self::Document,
429 E::Command => Self::Command,
430 E::Environment => Self::Environment,
431 E::BeginEnvironment => Self::BeginEnvironment,
432 E::EndEnvironment => Self::EndEnvironment,
433 E::MathMode => Self::MathMode,
434 E::InlineMath => Self::InlineMath,
435 E::DisplayMath => Self::DisplayMath,
436 E::Group => Self::Group,
437 E::Superscript => Self::Superscript,
438 E::Subscript => Self::Subscript,
439 E::Argument => Self::Argument,
440 E::OptionalArgument => Self::OptionalArgument,
441 E::MandatoryArgument => Self::MandatoryArgument,
442 E::Text => Self::Text,
443 E::Paragraph => Self::Paragraph,
444 E::Section => Self::Section,
445 E::Subsection => Self::Subsection,
446 E::Subsubsection => Self::Subsubsection,
447 E::List => Self::List,
448 E::Item => Self::Item,
449 E::Table => Self::Table,
450 E::Row => Self::Row,
451 E::Cell => Self::Cell,
452 E::Label => Self::Label,
453 E::Reference => Self::Reference,
454 E::Citation => Self::Citation,
455 E::Figure => Self::Figure,
456 E::Caption => Self::Caption,
457 E::Error => Self::Error,
458 E::DocumentClass => Self::DocumentClass,
459 E::UsePackage => Self::UsePackage,
460 E::Begin => Self::Begin,
461 E::End => Self::End,
462 E::Section_ => Self::Section_,
463 E::Subsection_ => Self::Subsection_,
464 E::Subsubsection_ => Self::Subsubsection_,
465 E::Chapter => Self::Chapter,
466 E::Part => Self::Part,
467 E::Title => Self::Title,
468 E::Author => Self::Author,
469 E::Date => Self::Date,
470 E::MakeTitle => Self::MakeTitle,
471 E::TableOfContents => Self::TableOfContents,
472 E::NewPage => Self::NewPage,
473 E::ClearPage => Self::ClearPage,
474 E::Frac => Self::Frac,
475 E::Sqrt => Self::Sqrt,
476 E::Sum => Self::Sum,
477 E::Int => Self::Int,
478 E::Lim => Self::Lim,
479 E::Alpha => Self::Alpha,
480 E::Beta => Self::Beta,
481 E::Gamma => Self::Gamma,
482 E::Delta => Self::Delta,
483 E::Epsilon => Self::Epsilon,
484 E::Zeta => Self::Zeta,
485 E::Eta => Self::Eta,
486 E::Theta => Self::Theta,
487 E::Iota => Self::Iota,
488 E::Kappa => Self::Kappa,
489 E::Lambda => Self::Lambda,
490 E::Mu => Self::Mu,
491 E::Nu => Self::Nu,
492 E::Xi => Self::Xi,
493 E::Omicron => Self::Omicron,
494 E::Pi => Self::Pi,
495 E::Rho => Self::Rho,
496 E::Sigma => Self::Sigma,
497 E::Tau => Self::Tau,
498 E::Upsilon => Self::Upsilon,
499 E::Phi => Self::Phi,
500 E::Chi => Self::Chi,
501 E::Psi => Self::Psi,
502 E::Omega => Self::Omega,
503 E::VarEpsilon => Self::VarEpsilon,
504 E::VarTheta => Self::VarTheta,
505 E::VarKappa => Self::VarKappa,
506 E::VarPi => Self::VarPi,
507 E::VarRho => Self::VarRho,
508 E::VarSigma => Self::VarSigma,
509 E::VarPhi => Self::VarPhi,
510 E::UpperGamma => Self::UpperGamma,
511 E::UpperDelta => Self::UpperDelta,
512 E::UpperTheta => Self::UpperTheta,
513 E::UpperLambda => Self::UpperLambda,
514 E::UpperXi => Self::UpperXi,
515 E::UpperPi => Self::UpperPi,
516 E::UpperSigma => Self::UpperSigma,
517 E::UpperUpsilon => Self::UpperUpsilon,
518 E::UpperPhi => Self::UpperPhi,
519 E::UpperPsi => Self::UpperPsi,
520 E::UpperOmega => Self::UpperOmega,
521 E::TextBf => Self::TextBf,
522 E::TextIt => Self::TextIt,
523 E::TextSc => Self::TextSc,
524 E::TextTt => Self::TextTt,
525 E::Emph => Self::Emph,
526 E::Underline => Self::Underline,
527 E::Identifier => Self::Identifier,
528 E::StringLiteral => Self::StringLiteral,
529 E::Number => Self::Number,
530 E::Backslash => Self::Backslash,
531 E::LeftBrace => Self::LeftBrace,
532 E::RightBrace => Self::RightBrace,
533 E::LeftBracket => Self::LeftBracket,
534 E::RightBracket => Self::RightBracket,
535 E::LeftParen => Self::LeftParen,
536 E::RightParen => Self::RightParen,
537 E::Dollar => Self::Dollar,
538 E::DoubleDollar => Self::DoubleDollar,
539 E::Ampersand => Self::Ampersand,
540 E::Percent => Self::Percent,
541 E::Hash => Self::Hash,
542 E::Caret => Self::Caret,
543 E::Underscore => Self::Underscore,
544 E::Tilde => Self::Tilde,
545 E::Equal => Self::Equal,
546 E::Equals => Self::Equals,
547 E::Plus => Self::Plus,
548 E::Minus => Self::Minus,
549 E::Star => Self::Star,
550 E::Slash => Self::Slash,
551 E::Pipe => Self::Pipe,
552 E::Less => Self::Less,
553 E::LessThan => Self::LessThan,
554 E::Greater => Self::Greater,
555 E::GreaterThan => Self::GreaterThan,
556 E::Exclamation => Self::Exclamation,
557 E::Question => Self::Question,
558 E::At => Self::At,
559 E::Colon => Self::Colon,
560 E::Semicolon => Self::Semicolon,
561 E::Comma => Self::Comma,
562 E::Dot => Self::Dot,
563 E::Comment => Self::Comment,
564 E::Whitespace => Self::Whitespace,
565 E::Newline => Self::Newline,
566 E::BeginKeyword => Self::BeginKeyword,
567 E::EndKeyword => Self::EndKeyword,
568 E::DocumentclassKeyword => Self::DocumentclassKeyword,
569 E::UsepackageKeyword => Self::UsepackageKeyword,
570 E::SectionKeyword => Self::SectionKeyword,
571 E::SubsectionKeyword => Self::SubsectionKeyword,
572 E::SubsubsectionKeyword => Self::SubsubsectionKeyword,
573 E::ChapterKeyword => Self::ChapterKeyword,
574 E::PartKeyword => Self::PartKeyword,
575 E::TitleKeyword => Self::TitleKeyword,
576 E::AuthorKeyword => Self::AuthorKeyword,
577 E::DateKeyword => Self::DateKeyword,
578 E::MaketitleKeyword => Self::MaketitleKeyword,
579 E::TableofcontentsKeyword => Self::TableofcontentsKeyword,
580 E::ItemKeyword => Self::ItemKeyword,
581 E::LabelKeyword => Self::LabelKeyword,
582 E::RefKeyword => Self::RefKeyword,
583 E::CiteKeyword => Self::CiteKeyword,
584 E::IncludegraphicsKeyword => Self::IncludegraphicsKeyword,
585 E::TextbfKeyword => Self::TextbfKeyword,
586 E::TextitKeyword => Self::TextitKeyword,
587 E::EmphKeyword => Self::EmphKeyword,
588 E::Eof => Self::Eof,
589 }
590 }
591}