1pub mod ast;
16pub mod dialect;
17pub mod error;
18pub mod parsed_file;
19pub mod plpgsql;
20pub mod split;
21
22pub mod backend;
23
24pub use ast::*;
25pub use dialect::Dialect;
26pub use error::ParseError;
27pub use parsed_file::ParsedFile;
28
29pub fn parse(source: &str, dialect: Dialect) -> ParsedFile {
40 if !matches!(dialect, Dialect::Postgres) {
42 #[cfg(feature = "sqlparser")]
43 {
44 return backend::sqlparser::parse(source, dialect);
45 }
46 #[cfg(not(feature = "sqlparser"))]
47 {
48 let range = text_size::TextRange::up_to(text_size::TextSize::of(source));
49 return ParsedFile {
50 statements: vec![Statement { range, kind: StatementKind::Unknown { text: source.to_string() } }],
51 errors: vec![ParseError { range, message: format!("sqlparser backend disabled; cannot parse {:?}", dialect) }],
52 };
53 }
54 }
55 #[cfg(feature = "pg_query_backend")]
57 {
58 backend::pg_query::parse(source, dialect)
59 }
60 #[cfg(all(not(feature = "pg_query_backend"), feature = "sqlparser"))]
61 {
62 return backend::sqlparser::parse(source, dialect);
63 }
64 #[cfg(all(not(feature = "pg_query_backend"), not(feature = "sqlparser")))]
65 {
66 let range = text_size::TextRange::up_to(text_size::TextSize::of(source));
67 ParsedFile {
68 statements: vec![Statement { range, kind: StatementKind::Unknown { text: source.to_string() } }],
69 errors: vec![ParseError { range, message: "no parser backend enabled".into() }],
70 }
71 }
72}