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