oak_tex/kind/
mod.rs

1use oak_core::SyntaxKind;
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
23    // 参数和选项
24    Argument,
25    OptionalArgument,
26    MandatoryArgument,
27
28    // 文本和内容
29    Text,
30    Paragraph,
31    Section,
32    Subsection,
33    Subsubsection,
34
35    // 列表和表格
36    List,
37    Item,
38    Table,
39    Row,
40    Cell,
41
42    // 引用和标签
43    Label,
44    Reference,
45    Citation,
46
47    // 图形和浮动体
48    Figure,
49    Caption,
50
51    // 错误节点
52    Error,
53
54    // TeX 关键字和命令
55    DocumentClass,
56    UsePackage,
57    Begin,
58    End,
59    Section_,
60    Subsection_,
61    Subsubsection_,
62    Chapter,
63    Part,
64    Title,
65    Author,
66    Date,
67    MakeTitle,
68    TableOfContents,
69    NewPage,
70    ClearPage,
71
72    // 新增的关键字变体
73    BeginKeyword,
74    EndKeyword,
75    DocumentclassKeyword,
76    UsepackageKeyword,
77    SectionKeyword,
78    SubsectionKeyword,
79    SubsubsectionKeyword,
80    ChapterKeyword,
81    PartKeyword,
82    TitleKeyword,
83    AuthorKeyword,
84    DateKeyword,
85    MaketitleKeyword,
86    TableofcontentsKeyword,
87    ItemKeyword,
88    LabelKeyword,
89    RefKeyword,
90    CiteKeyword,
91    IncludegraphicsKeyword,
92    TextbfKeyword,
93    TextitKeyword,
94    EmphKeyword,
95
96    // 数学命令
97    Frac,
98    Sqrt,
99    Sum,
100    Int,
101    Lim,
102    Alpha,
103    Beta,
104    Gamma,
105    Delta,
106    Epsilon,
107
108    // 格式化命令
109    TextBf,
110    TextIt,
111    TextSc,
112    TextTt,
113    Emph,
114    Underline,
115
116    // 标识符和字面量
117    Identifier,
118    StringLiteral,
119    Number,
120
121    // 操作符和标点符号
122    Backslash,
123    LeftBrace,
124    RightBrace,
125    LeftBracket,
126    RightBracket,
127    LeftParen,
128    RightParen,
129    Dollar,
130    DoubleDollar,
131    Ampersand,
132    Percent,
133    Hash,
134    Caret,
135    Underscore,
136    Tilde,
137
138    // 特殊字符
139    Equal,
140    Equals,
141    Plus,
142    Minus,
143    Star,
144    Slash,
145    Pipe,
146    Less,
147    LessThan,
148    Greater,
149    GreaterThan,
150    Exclamation,
151    Question,
152    At,
153    Colon,
154    Semicolon,
155    Comma,
156    Dot,
157
158    // 空白和注释
159    Comment,
160    Whitespace,
161    Newline,
162
163    // 文件结束
164    Eof,
165}
166
167impl SyntaxKind for TexSyntaxKind {
168    fn is_trivia(&self) -> bool {
169        matches!(self, Self::Whitespace | Self::Newline | Self::Comment)
170    }
171
172    fn is_comment(&self) -> bool {
173        matches!(self, Self::Comment)
174    }
175
176    fn is_whitespace(&self) -> bool {
177        matches!(self, Self::Whitespace | Self::Newline)
178    }
179
180    fn is_token_type(&self) -> bool {
181        !matches!(
182            self,
183            Self::Document
184                | Self::Command
185                | Self::Environment
186                | Self::Argument
187                | Self::OptionalArgument
188                | Self::MandatoryArgument
189                | Self::Text
190                | Self::List
191                | Self::Table
192                | Self::Reference
193                | Self::Figure
194                | Self::Error
195        )
196    }
197
198    fn is_element_type(&self) -> bool {
199        matches!(
200            self,
201            Self::Document
202                | Self::Command
203                | Self::Environment
204                | Self::Argument
205                | Self::OptionalArgument
206                | Self::MandatoryArgument
207                | Self::Text
208                | Self::List
209                | Self::Table
210                | Self::Reference
211                | Self::Figure
212                | Self::Error
213        )
214    }
215}