use crate::ast::SQLStatement;
use crate::errors::predule::ParsingError;
use crate::errors::RRDBError;
use crate::lexer::predule::Token;
use crate::parser::context::ParserContext;
use crate::parser::predule::Parser;
impl Parser {
pub(crate) fn handle_create_query(
&mut self,
context: ParserContext,
) -> Result<SQLStatement, RRDBError> {
if !self.has_next_token() {
return Err(ParsingError::wrap("E1101 need more tokens"));
}
let current_token = self.get_next_token();
match current_token {
Token::Table => self.handle_create_table_query(context),
Token::Database => self.handle_create_database_query(),
_ => Err(ParsingError::wrap(format!(
"E1102 not supported command. possible commands: (create table). but your input is {:?}",
current_token
))),
}
}
pub(crate) fn handle_alter_query(
&mut self,
context: ParserContext,
) -> Result<SQLStatement, RRDBError> {
if !self.has_next_token() {
return Err(ParsingError::wrap("E1103 need more tokens"));
}
let current_token = self.get_next_token();
match current_token {
Token::Table => self.handle_alter_table_query(context),
Token::Database => self.handle_alter_database_query(),
_ => Err(ParsingError::wrap(
"E1104 not supported command. possible commands: (alter table)",
)),
}
}
pub(crate) fn handle_drop_query(
&mut self,
context: ParserContext,
) -> Result<SQLStatement, RRDBError> {
if !self.has_next_token() {
return Err(ParsingError::wrap("E1105 need more tokens"));
}
let current_token = self.get_next_token();
match current_token {
Token::Table => self.handle_drop_table_query(context),
Token::Database => self.handle_drop_database_query(),
_ => Err(ParsingError::wrap(
"E1106 not supported command. possible commands: (create table)",
)),
}
}
}