oak_sql/parser/
element_type.rs1use oak_core::{ElementType, UniversalElementRole};
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
6pub enum SqlElementType {
7 Root,
9 ExplainStatement,
11 TransactionStatement,
13 PragmaStatement,
15 ShowStatement,
17 SelectStatement,
19 VectorSearch,
21 Identifier,
23 Expression,
25 ErrorNode,
27 InsertStatement,
29 UpdateStatement,
31 DeleteStatement,
33 CreateStatement,
35 DropStatement,
37 AlterStatement,
39 JoinClause,
41 GroupByClause,
43 HavingClause,
45 OrderByClause,
47 LimitClause,
49 TableName,
51 ColumnName,
53 SelectItem,
55 Alias,
57 ColumnDefinition,
59 ValueList,
61 Assignment,
63 AlterAction,
65 ReturningClause,
67 ConflictClause,
69 Subquery,
71 FunctionCall,
73}
74
75impl ElementType for SqlElementType {
76 type Role = UniversalElementRole;
77
78 fn role(&self) -> UniversalElementRole {
79 use UniversalElementRole::*;
80 match self {
81 Self::Root => Root,
82 Self::Identifier | Self::TableName | Self::ColumnName | Self::Alias => Name,
83 Self::Expression | Self::FunctionCall => Expression,
84 Self::ErrorNode => Error,
85 Self::SelectStatement
86 | Self::InsertStatement
87 | Self::UpdateStatement
88 | Self::DeleteStatement
89 | Self::CreateStatement
90 | Self::DropStatement
91 | Self::AlterStatement
92 | Self::ExplainStatement
93 | Self::TransactionStatement
94 | Self::PragmaStatement
95 | Self::ShowStatement => Statement,
96 Self::JoinClause
97 | Self::GroupByClause
98 | Self::HavingClause
99 | Self::OrderByClause
100 | Self::LimitClause
101 | Self::SelectItem
102 | Self::ColumnDefinition
103 | Self::ValueList
104 | Self::Assignment
105 | Self::AlterAction
106 | Self::ReturningClause
107 | Self::ConflictClause
108 | Self::VectorSearch
109 | Self::Subquery => Statement,
110 }
111 }
112}
113
114impl From<crate::lexer::token_type::SqlTokenType> for SqlElementType {
115 fn from(token: crate::lexer::token_type::SqlTokenType) -> Self {
116 match token {
117 crate::lexer::token_type::SqlTokenType::Root => Self::Root,
118 crate::lexer::token_type::SqlTokenType::ExplainStatement => Self::ExplainStatement,
119 crate::lexer::token_type::SqlTokenType::TransactionStatement => Self::TransactionStatement,
120 crate::lexer::token_type::SqlTokenType::PragmaStatement => Self::PragmaStatement,
121 crate::lexer::token_type::SqlTokenType::ShowStatement => Self::ShowStatement,
122 crate::lexer::token_type::SqlTokenType::SelectStatement => Self::SelectStatement,
123 crate::lexer::token_type::SqlTokenType::InsertStatement => Self::InsertStatement,
124 crate::lexer::token_type::SqlTokenType::UpdateStatement => Self::UpdateStatement,
125 crate::lexer::token_type::SqlTokenType::DeleteStatement => Self::DeleteStatement,
126 crate::lexer::token_type::SqlTokenType::CreateStatement => Self::CreateStatement,
127 crate::lexer::token_type::SqlTokenType::DropStatement => Self::DropStatement,
128 crate::lexer::token_type::SqlTokenType::AlterStatement => Self::AlterStatement,
129 crate::lexer::token_type::SqlTokenType::Expression => Self::Expression,
130 crate::lexer::token_type::SqlTokenType::Identifier => Self::Identifier,
131 crate::lexer::token_type::SqlTokenType::TableName => Self::TableName,
132 crate::lexer::token_type::SqlTokenType::ColumnName => Self::ColumnName,
133 crate::lexer::token_type::SqlTokenType::JoinClause => Self::JoinClause,
134 crate::lexer::token_type::SqlTokenType::GroupByClause => Self::GroupByClause,
135 crate::lexer::token_type::SqlTokenType::HavingClause => Self::HavingClause,
136 crate::lexer::token_type::SqlTokenType::OrderByClause => Self::OrderByClause,
137 crate::lexer::token_type::SqlTokenType::LimitClause => Self::LimitClause,
138 crate::lexer::token_type::SqlTokenType::SelectItem => Self::SelectItem,
139 crate::lexer::token_type::SqlTokenType::Alias => Self::Alias,
140 crate::lexer::token_type::SqlTokenType::ColumnDefinition => Self::ColumnDefinition,
141 crate::lexer::token_type::SqlTokenType::ValueList => Self::ValueList,
142 crate::lexer::token_type::SqlTokenType::Assignment => Self::Assignment,
143 crate::lexer::token_type::SqlTokenType::AlterAction => Self::AlterAction,
144 crate::lexer::token_type::SqlTokenType::ErrorNode => Self::ErrorNode,
145 _ => Self::ErrorNode,
146 }
147 }
148}