Skip to main content

alopex_sql/
dialect.rs

1/// SQL方言ごとのカスタマイズポイントを提供するトrait。
2pub trait Dialect: std::fmt::Debug {
3    /// 識別子の先頭として利用可能な文字かを判定する。
4    fn is_identifier_start(&self, ch: char) -> bool;
5
6    /// 識別子の残りの文字として利用可能な文字かを判定する。
7    fn is_identifier_part(&self, ch: char) -> bool;
8
9    /// 方言名。
10    fn name(&self) -> &'static str;
11}
12
13/// Alopex標準のSQL方言。
14#[derive(Debug, Default, Clone)]
15pub struct AlopexDialect;
16
17impl Dialect for AlopexDialect {
18    fn is_identifier_start(&self, ch: char) -> bool {
19        ch == '_' || ch.is_ascii_alphabetic()
20    }
21
22    fn is_identifier_part(&self, ch: char) -> bool {
23        ch == '_' || ch.is_ascii_alphanumeric()
24    }
25
26    fn name(&self) -> &'static str {
27        "alopex"
28    }
29}