oak_typst/kind/
mod.rs

1use oak_core::SyntaxKind;
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
5pub enum TypstSyntaxKind {
6    // 节点种类
7    Root,
8    Document,
9    Block,
10
11    // 内容元素
12    Heading,
13    Paragraph,
14    List,
15    ListItem,
16    Table,
17    TableRow,
18    TableCell,
19    Figure,
20    Image,
21    Link,
22
23    // 文本元素
24    Text,
25    Strong,
26    Emphasis,
27    Code,
28    Math,
29    InlineMath,
30    DisplayMath,
31    Raw,
32    Quote,
33
34    // 脚本元素
35    Script,
36    Expression,
37    FunctionCall,
38    Variable,
39    Assignment,
40    Conditional,
41    Loop,
42    Import,
43    Include,
44
45    // 样式元素
46    Set,
47    Show,
48    Style,
49    Color,
50    Font,
51    Size,
52
53    // 关键字
54    Let,
55    If,
56    Else,
57    For,
58    While,
59    Break,
60    Continue,
61    Return,
62    True,
63    False,
64
65    // 操作符
66    Plus,
67    Minus,
68    Star,
69    Slash,
70    Percent,
71    Equal,
72    EqualEqual,
73    NotEqual,
74    Less,
75    Greater,
76    LessEqual,
77    GreaterEqual,
78    And,
79    Or,
80    Not,
81
82    // 标点符号
83    LeftParen,
84    RightParen,
85    LeftBrace,
86    RightBrace,
87    LeftBracket,
88    RightBracket,
89    Semicolon,
90    Comma,
91    Dot,
92    Colon,
93    Hash,
94    At,
95    Dollar,
96    Underscore,
97
98    // 字面量
99    StringLiteral,
100    NumericLiteral,
101    Identifier,
102
103    // 注释和空白
104    LineComment,
105    BlockComment,
106    Whitespace,
107    Newline,
108
109    // 特殊符号
110    Eof,
111    Error,
112}
113
114impl SyntaxKind for TypstSyntaxKind {
115    fn is_trivia(&self) -> bool {
116        matches!(
117            self,
118            TypstSyntaxKind::Whitespace
119                | TypstSyntaxKind::Newline
120                | TypstSyntaxKind::LineComment
121                | TypstSyntaxKind::BlockComment
122        )
123    }
124
125    fn is_comment(&self) -> bool {
126        matches!(self, TypstSyntaxKind::LineComment | TypstSyntaxKind::BlockComment)
127    }
128
129    fn is_whitespace(&self) -> bool {
130        matches!(self, TypstSyntaxKind::Whitespace | TypstSyntaxKind::Newline)
131    }
132
133    fn is_token_type(&self) -> bool {
134        !matches!(
135            self,
136            TypstSyntaxKind::Root
137                | TypstSyntaxKind::Document
138                | TypstSyntaxKind::Block
139                | TypstSyntaxKind::Heading
140                | TypstSyntaxKind::Paragraph
141                | TypstSyntaxKind::List
142                | TypstSyntaxKind::ListItem
143                | TypstSyntaxKind::Table
144                | TypstSyntaxKind::TableRow
145                | TypstSyntaxKind::TableCell
146                | TypstSyntaxKind::Figure
147                | TypstSyntaxKind::Image
148                | TypstSyntaxKind::Link
149                | TypstSyntaxKind::Text
150                | TypstSyntaxKind::Strong
151                | TypstSyntaxKind::Emphasis
152                | TypstSyntaxKind::Code
153                | TypstSyntaxKind::Math
154                | TypstSyntaxKind::InlineMath
155                | TypstSyntaxKind::DisplayMath
156                | TypstSyntaxKind::Raw
157                | TypstSyntaxKind::Quote
158                | TypstSyntaxKind::Script
159                | TypstSyntaxKind::Expression
160                | TypstSyntaxKind::FunctionCall
161                | TypstSyntaxKind::Variable
162                | TypstSyntaxKind::Assignment
163                | TypstSyntaxKind::Conditional
164                | TypstSyntaxKind::Loop
165                | TypstSyntaxKind::Style
166        )
167    }
168
169    fn is_element_type(&self) -> bool {
170        matches!(
171            self,
172            TypstSyntaxKind::Root
173                | TypstSyntaxKind::Document
174                | TypstSyntaxKind::Block
175                | TypstSyntaxKind::Heading
176                | TypstSyntaxKind::Paragraph
177                | TypstSyntaxKind::List
178                | TypstSyntaxKind::ListItem
179                | TypstSyntaxKind::Table
180                | TypstSyntaxKind::TableRow
181                | TypstSyntaxKind::TableCell
182                | TypstSyntaxKind::Figure
183                | TypstSyntaxKind::Image
184                | TypstSyntaxKind::Link
185                | TypstSyntaxKind::Text
186                | TypstSyntaxKind::Strong
187                | TypstSyntaxKind::Emphasis
188                | TypstSyntaxKind::Code
189                | TypstSyntaxKind::Math
190                | TypstSyntaxKind::InlineMath
191                | TypstSyntaxKind::DisplayMath
192                | TypstSyntaxKind::Raw
193                | TypstSyntaxKind::Quote
194                | TypstSyntaxKind::Script
195                | TypstSyntaxKind::Expression
196                | TypstSyntaxKind::FunctionCall
197                | TypstSyntaxKind::Variable
198                | TypstSyntaxKind::Assignment
199                | TypstSyntaxKind::Conditional
200                | TypstSyntaxKind::Loop
201                | TypstSyntaxKind::Style
202        )
203    }
204}