Skip to main content

oak_tex/kind/
mod.rs

1use oak_core::{ElementType, TokenType, UniversalElementRole, UniversalTokenRole};
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
5pub enum TexSyntaxKind {
6    // 节点种类
7    Root,
8    SourceFile,
9    Document,
10
11    // TeX 命令和环境
12    Command,
13    Environment,
14    BeginEnvironment,
15    EndEnvironment,
16
17    // TeX 特殊结构
18    MathMode,
19    InlineMath,
20    DisplayMath,
21    Group,
22    Superscript,
23    Subscript,
24
25    // 参数和选项
26    Argument,
27    OptionalArgument,
28    MandatoryArgument,
29
30    // 文本和内容
31    Text,
32    Paragraph,
33    Section,
34    Subsection,
35    Subsubsection,
36
37    // 列表和表格
38    List,
39    Item,
40    Table,
41    Row,
42    Cell,
43
44    // 引用和标签
45    Label,
46    Reference,
47    Citation,
48
49    // 图形和浮动体
50    Figure,
51    Caption,
52
53    // 错误节点
54    Error,
55
56    // TeX 关键字和命令
57    DocumentClass,
58    UsePackage,
59    Begin,
60    End,
61    Section_,
62    Subsection_,
63    Subsubsection_,
64    Chapter,
65    Part,
66    Title,
67    Author,
68    Date,
69    MakeTitle,
70    TableOfContents,
71    NewPage,
72    ClearPage,
73
74    // 新增的关键字变体
75    BeginKeyword,
76    EndKeyword,
77    DocumentclassKeyword,
78    UsepackageKeyword,
79    SectionKeyword,
80    SubsectionKeyword,
81    SubsubsectionKeyword,
82    ChapterKeyword,
83    PartKeyword,
84    TitleKeyword,
85    AuthorKeyword,
86    DateKeyword,
87    MaketitleKeyword,
88    TableofcontentsKeyword,
89    ItemKeyword,
90    LabelKeyword,
91    RefKeyword,
92    CiteKeyword,
93    IncludegraphicsKeyword,
94    TextbfKeyword,
95    TextitKeyword,
96    EmphKeyword,
97
98    // 数学命令
99    Frac,
100    Sqrt,
101    Sum,
102    Int,
103    Lim,
104    Alpha,
105    Beta,
106    Gamma,
107    Delta,
108    Epsilon,
109    Zeta,
110    Eta,
111    Theta,
112    Iota,
113    Kappa,
114    Lambda,
115    Mu,
116    Nu,
117    Xi,
118    Omicron,
119    Pi,
120    Rho,
121    Sigma,
122    Tau,
123    Upsilon,
124    Phi,
125    Chi,
126    Psi,
127    Omega,
128    VarEpsilon,
129    VarTheta,
130    VarKappa,
131    VarPi,
132    VarRho,
133    VarSigma,
134    VarPhi,
135    UpperGamma,
136    UpperDelta,
137    UpperTheta,
138    UpperLambda,
139    UpperXi,
140    UpperPi,
141    UpperSigma,
142    UpperUpsilon,
143    UpperPhi,
144    UpperPsi,
145    UpperOmega,
146
147    // 格式化命令
148    TextBf,
149    TextIt,
150    TextSc,
151    TextTt,
152    Emph,
153    Underline,
154
155    // 标识符和字面量
156    Identifier,
157    StringLiteral,
158    Number,
159
160    // 操作符和标点符号
161    Backslash,
162    LeftBrace,
163    RightBrace,
164    LeftBracket,
165    RightBracket,
166    LeftParen,
167    RightParen,
168    Dollar,
169    DoubleDollar,
170    Ampersand,
171    Percent,
172    Hash,
173    Caret,
174    Underscore,
175    Tilde,
176
177    // 特殊字符
178    Equal,
179    Equals,
180    Plus,
181    Minus,
182    Star,
183    Slash,
184    Pipe,
185    Less,
186    LessThan,
187    Greater,
188    GreaterThan,
189    Exclamation,
190    Question,
191    At,
192    Colon,
193    Semicolon,
194    Comma,
195    Dot,
196
197    // 空白和注释
198    Comment,
199    Whitespace,
200    Newline,
201
202    // 文件结束
203    Eof,
204}
205
206impl TokenType for TexSyntaxKind {
207    const END_OF_STREAM: Self = Self::Eof;
208    type Role = UniversalTokenRole;
209
210    fn role(&self) -> Self::Role {
211        match self {
212            Self::Whitespace | Self::Newline => UniversalTokenRole::Whitespace,
213            Self::Comment => UniversalTokenRole::Comment,
214            Self::Eof => UniversalTokenRole::Eof,
215            _ => UniversalTokenRole::None,
216        }
217    }
218}
219
220impl ElementType for TexSyntaxKind {
221    type Role = UniversalElementRole;
222
223    fn role(&self) -> Self::Role {
224        match self {
225            Self::Root | Self::SourceFile => UniversalElementRole::Root,
226            Self::Error => UniversalElementRole::Error,
227            _ => UniversalElementRole::None,
228        }
229    }
230}