use std::collections::HashSet;
use thiserror::Error;
use crate::ast;
const ERR_PARSE: &str = "parser error";
const ERR_MISSING_GROUP_BY: &str = "Non-grouped RETURN expressions must appear in GROUP BY clause";
const ERR_UNALIASED_COMPLEX: &str = "Complex expression must have an alias";
const ERR_ID_NOT_IN_SCOPE: &str = "Identifier not found in current scope";
pub trait QueryParser: Send + Sync {
fn parse(&self, input: &str) -> Result<ast::Query, QueryParseError>;
}
pub trait QueryConfiguration: Send + Sync {
fn get_aggregating_function_names(&self) -> HashSet<String>;
}
#[derive(Error, Debug)]
pub enum QueryParseError {
#[error("{ERR_PARSE}: {0}")]
ParserError(Box<dyn std::error::Error + Send + Sync>),
#[error("{ERR_MISSING_GROUP_BY}")]
MissingGroupByKey,
#[error("{ERR_UNALIASED_COMPLEX}: {0}")]
UnaliasedComplexExpression(String),
#[error("{ERR_ID_NOT_IN_SCOPE}: {0}")]
IdentifierNotInScope(String),
}
impl QueryParseError {
pub fn as_peg_error(&self) -> &'static str {
match self {
QueryParseError::ParserError(_) => ERR_PARSE,
QueryParseError::MissingGroupByKey => ERR_MISSING_GROUP_BY,
QueryParseError::UnaliasedComplexExpression(_) => ERR_UNALIASED_COMPLEX,
QueryParseError::IdentifierNotInScope(_) => ERR_ID_NOT_IN_SCOPE,
}
}
}