oak_sql/kind/
mod.rs

1/// 统一SQL 语法种类(包含节点与词法
2#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, serde::Serialize)]
3pub enum SqlSyntaxKind {
4    // 节点种类
5    Root,
6    Statement,
7    SelectStatement,
8    InsertStatement,
9    UpdateStatement,
10    DeleteStatement,
11    CreateStatement,
12    DropStatement,
13    AlterStatement,
14    Expression,
15    Identifier,
16    TableName,
17    ColumnName,
18    ErrorNode,
19
20    // 空白字符和换
21    Whitespace,
22    Newline,
23
24    // 注释
25    Comment,
26    LineComment,
27    BlockComment,
28
29    // 字面
30    NumberLiteral,
31    FloatLiteral,
32    StringLiteral,
33    BooleanLiteral,
34    NullLiteral,
35
36    // 标识
37    Identifier_,
38
39    // SQL 关键
40    Select,
41    From,
42    Where,
43    Insert,
44    Into,
45    Values,
46    Update,
47    Set,
48    Delete,
49    Create,
50    Table,
51    Drop,
52    Alter,
53    Add,
54    Column,
55    Primary,
56    Key,
57    Foreign,
58    References,
59    Index,
60    Unique,
61    Not,
62    Null,
63    Default,
64    AutoIncrement,
65    And,
66    Or,
67    In,
68    Like,
69    Between,
70    Is,
71    As,
72    Join,
73    Inner,
74    Left,
75    Right,
76    Full,
77    Outer,
78    On,
79    Group,
80    By,
81    Having,
82    Order,
83    Asc,
84    Desc,
85    Limit,
86    Offset,
87    Union,
88    All,
89    Distinct,
90    Count,
91    Sum,
92    Avg,
93    Min,
94    Max,
95    View,
96    Database,
97    Schema,
98    True,
99    False,
100    Exists,
101    Case,
102    When,
103    Then,
104    Else,
105    End,
106    If,
107    Begin,
108    Commit,
109    Rollback,
110    Transaction,
111
112    // 数据类型
113    Int,
114    Integer,
115    Varchar,
116    Char,
117    Text,
118    Date,
119    Time,
120    Timestamp,
121    Decimal,
122    Float,
123    Double,
124    Boolean,
125
126    // 操作符
127    Plus,
128    Minus,
129    Star,
130    Slash,
131    Percent,
132    Equal,
133    NotEqual,
134    Less,
135    Greater,
136    LessEqual,
137    GreaterEqual,
138    Assign,
139    Eq,
140    Ne,
141    Lt,
142    Le,
143    Gt,
144    Ge,
145    Concat,
146
147    // 分隔符
148    LeftParen,
149    RightParen,
150    LeftBracket,
151    RightBracket,
152    LeftBrace,
153    RightBrace,
154    Comma,
155    Semicolon,
156    Dot,
157    Colon,
158    Question,
159
160    // 错误和结
161    Error,
162    Eof,
163}
164
165impl oak_core::SyntaxKind for SqlSyntaxKind {
166    fn is_trivia(&self) -> bool {
167        matches!(
168            self,
169            SqlSyntaxKind::Whitespace
170                | SqlSyntaxKind::Newline
171                | SqlSyntaxKind::Comment
172                | SqlSyntaxKind::LineComment
173                | SqlSyntaxKind::BlockComment
174        )
175    }
176
177    fn is_comment(&self) -> bool {
178        matches!(self, SqlSyntaxKind::Comment | SqlSyntaxKind::LineComment | SqlSyntaxKind::BlockComment)
179    }
180
181    fn is_whitespace(&self) -> bool {
182        matches!(self, SqlSyntaxKind::Whitespace | SqlSyntaxKind::Newline)
183    }
184
185    fn is_token_type(&self) -> bool {
186        !self.is_element_type()
187    }
188
189    fn is_element_type(&self) -> bool {
190        matches!(
191            self,
192            SqlSyntaxKind::Root
193                | SqlSyntaxKind::Statement
194                | SqlSyntaxKind::SelectStatement
195                | SqlSyntaxKind::InsertStatement
196                | SqlSyntaxKind::UpdateStatement
197                | SqlSyntaxKind::DeleteStatement
198                | SqlSyntaxKind::CreateStatement
199                | SqlSyntaxKind::DropStatement
200                | SqlSyntaxKind::AlterStatement
201                | SqlSyntaxKind::Expression
202                | SqlSyntaxKind::Identifier
203                | SqlSyntaxKind::TableName
204                | SqlSyntaxKind::ColumnName
205                | SqlSyntaxKind::ErrorNode
206        )
207    }
208}