oak_wolfram/kind/
mod.rs

1use oak_core::SyntaxKind;
2use serde::{Deserialize, Serialize};
3
4#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
5pub enum WolframSyntaxKind {
6    // 基础 tokens
7    Whitespace,
8    Newline,
9
10    // 标识符和字面量
11    Identifier,
12    Integer,
13    Real,
14    String,
15
16    // 关键字
17    If,
18    Then,
19    Else,
20    While,
21    For,
22    Do,
23    Function,
24    Module,
25    Block,
26    With,
27    Table,
28    Map,
29    Apply,
30    Select,
31    Cases,
32    Rule,
33    RuleDelayed,
34    Set,
35    SetDelayed,
36    Unset,
37    Clear,
38    ClearAll,
39    Return,
40    Break,
41    Continue,
42    True,
43    False,
44    Null,
45    Export,
46    Import,
47
48    // 运算符
49    Plus,         // +
50    Minus,        // -
51    Times,        // *
52    Divide,       // /
53    Power,        // ^
54    Equal,        // ==
55    NotEqual,     // !=
56    Less,         // <
57    Greater,      // >
58    LessEqual,    // <=
59    GreaterEqual, // >=
60    And,          // &&
61    Or,           // ||
62    Not,          // !
63
64    // 赋值运算符
65    Assign,       // =
66    AddTo,        // +=
67    SubtractFrom, // -=
68    TimesBy,      // *=
69    DivideBy,     // /=
70
71    // 分隔符
72    LeftParen,    // (
73    RightParen,   // )
74    LeftBracket,  // [
75    RightBracket, // ]
76    LeftBrace,    // {
77    RightBrace,   // }
78    Comma,        // ,
79    Semicolon,    // ;
80    Colon,        // :
81    Dot,          // .
82
83    // 特殊符号
84    Arrow,            // ->
85    DoubleArrow,      // =>
86    Question,         // ?
87    Underscore,       // _
88    DoubleUnderscore, // __
89    TripleUnderscore, // ___
90    Slot,             // #
91    SlotSequence,     // ##
92
93    // 注释
94    Comment,
95
96    // 文本
97    Text,
98
99    // 错误处理
100    Error,
101
102    // EOF
103    Eof,
104}
105
106impl SyntaxKind for WolframSyntaxKind {
107    fn is_trivia(&self) -> bool {
108        matches!(self, WolframSyntaxKind::Whitespace | WolframSyntaxKind::Newline | WolframSyntaxKind::Comment)
109    }
110
111    fn is_comment(&self) -> bool {
112        matches!(self, WolframSyntaxKind::Comment)
113    }
114
115    fn is_whitespace(&self) -> bool {
116        matches!(self, WolframSyntaxKind::Whitespace | WolframSyntaxKind::Newline)
117    }
118
119    fn is_token_type(&self) -> bool {
120        !matches!(self, WolframSyntaxKind::Error | WolframSyntaxKind::Eof)
121    }
122
123    fn is_element_type(&self) -> bool {
124        matches!(self, WolframSyntaxKind::Error | WolframSyntaxKind::Eof)
125    }
126}