use log::error;
pub mod ast;
pub mod parse {
#![allow(unused_braces)]
#![allow(unused_comparisons)] #![allow(clippy::collapsible_if)]
#![allow(clippy::if_same_then_else)]
#![allow(clippy::absurd_extreme_comparisons)] #![allow(clippy::needless_return)]
#![allow(clippy::upper_case_acronyms)]
include!(concat!(env!("OUT_DIR"), "/parse.rs"));
}
use ast::{Cmd, ExplainKind, Name, Stmt};
#[derive(Debug)]
pub struct ParserError(String);
impl ParserError {
pub fn msg(self) -> String {
self.0
}
}
impl std::fmt::Display for ParserError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "parser error: {}", self.0,)
}
}
impl std::error::Error for ParserError {}
pub struct Context {
explain: Option<ExplainKind>,
stmt: Option<Stmt>,
constraint_name: Option<Name>, done: bool,
error: Option<String>,
}
impl Context {
pub fn new() -> Context {
Context {
explain: None,
stmt: None,
constraint_name: None,
done: false,
error: None,
}
}
pub fn cmd(&mut self) -> Option<Cmd> {
if let Some(stmt) = self.stmt.take() {
match self.explain.take() {
Some(ExplainKind::Explain) => Some(Cmd::Explain(stmt)),
Some(ExplainKind::QueryPlan) => Some(Cmd::ExplainQueryPlan(stmt)),
None => Some(Cmd::Stmt(stmt)),
}
} else {
None
}
}
fn constraint_name(&mut self) -> Option<Name> {
self.constraint_name.take()
}
fn no_constraint_name(&self) -> bool {
self.constraint_name.is_none()
}
fn sqlite3_error_msg(&mut self, msg: &str) {
error!("parser error: {}", msg);
}
fn sqlite3_finish_coding(&mut self) {
self.done = true;
}
pub fn done(&self) -> bool {
self.done || self.error.is_some()
}
pub fn is_ok(&self) -> bool {
self.error.is_none()
}
pub fn error(&mut self) -> Option<String> {
self.error.take()
}
pub fn reset(&mut self) {
self.explain = None;
self.stmt = None;
self.constraint_name = None;
self.done = false;
self.error = None;
}
}