Skip to main content

rigsql_dialects/
lib.rs

1use rigsql_lexer::LexerConfig;
2use rigsql_parser::Parser;
3use strum::{Display, EnumString};
4
5/// Supported SQL dialects.
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Display, EnumString)]
7#[strum(ascii_case_insensitive)]
8#[derive(Default)]
9pub enum DialectKind {
10    #[strum(serialize = "ansi")]
11    #[default]
12    Ansi,
13    #[strum(serialize = "postgres", serialize = "postgresql")]
14    Postgres,
15    #[strum(serialize = "tsql", serialize = "sqlserver")]
16    Tsql,
17}
18
19impl DialectKind {
20    /// Create a parser configured for this dialect.
21    pub fn parser(self) -> Parser {
22        Parser::new(self.lexer_config())
23    }
24
25    /// Get the lexer configuration for this dialect.
26    pub fn lexer_config(self) -> LexerConfig {
27        match self {
28            DialectKind::Ansi => LexerConfig::ansi(),
29            DialectKind::Postgres => LexerConfig::postgres(),
30            DialectKind::Tsql => LexerConfig::tsql(),
31        }
32    }
33
34    /// Returns the dialect name as a static string slice.
35    pub fn as_str(self) -> &'static str {
36        match self {
37            DialectKind::Ansi => "ansi",
38            DialectKind::Postgres => "postgres",
39            DialectKind::Tsql => "tsql",
40        }
41    }
42}