pub mod ast;
pub mod dialect;
pub mod error;
pub mod parsed_file;
pub mod plpgsql;
pub mod split;
pub mod backend;
pub use ast::*;
pub use dialect::Dialect;
pub use error::ParseError;
pub use parsed_file::ParsedFile;
pub fn parse(source: &str, dialect: Dialect) -> ParsedFile {
if !matches!(dialect, Dialect::Postgres) {
#[cfg(feature = "sqlparser")]
{
return backend::sqlparser::parse(source, dialect);
}
#[cfg(not(feature = "sqlparser"))]
{
let range = text_size::TextRange::up_to(text_size::TextSize::of(source));
return ParsedFile {
statements: vec![Statement { range, kind: StatementKind::Unknown { text: source.to_string() } }],
errors: vec![ParseError { range, message: format!("sqlparser backend disabled; cannot parse {:?}", dialect) }],
};
}
}
#[cfg(feature = "pg_query_backend")]
{
backend::pg_query::parse(source, dialect)
}
#[cfg(all(not(feature = "pg_query_backend"), feature = "sqlparser"))]
{
return backend::sqlparser::parse(source, dialect);
}
#[cfg(all(not(feature = "pg_query_backend"), not(feature = "sqlparser")))]
{
let range = text_size::TextRange::up_to(text_size::TextSize::of(source));
ParsedFile {
statements: vec![Statement { range, kind: StatementKind::Unknown { text: source.to_string() } }],
errors: vec![ParseError { range, message: "no parser backend enabled".into() }],
}
}
}