Skip to content

Commit 5ec623e

Browse files
authored
db dialect, backtick mod (#10)
1 parent 8dcc913 commit 5ec623e

3 files changed

Lines changed: 40 additions & 1 deletion

File tree

src/dialect/databricks.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Licensed under the Apache License, Version 2.0 (the "License");
2+
// you may not use this file except in compliance with the License.
3+
// You may obtain a copy of the License at
4+
//
5+
// http://www.apache.org/licenses/LICENSE-2.0
6+
//
7+
// Unless required by applicable law or agreed to in writing, software
8+
// distributed under the License is distributed on an "AS IS" BASIS,
9+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
// See the License for the specific language governing permissions and
11+
// limitations under the License.
12+
13+
use crate::dialect::Dialect;
14+
15+
#[derive(Debug)]
16+
pub struct DatabricksDialect {}
17+
18+
// derived from AnsiDialect, but modified with backtick identifier
19+
impl Dialect for DatabricksDialect {
20+
fn is_identifier_start(&self, ch: char) -> bool {
21+
('a'..='z').contains(&ch) || ('A'..='Z').contains(&ch)
22+
}
23+
24+
fn is_identifier_part(&self, ch: char) -> bool {
25+
('a'..='z').contains(&ch)
26+
|| ('A'..='Z').contains(&ch)
27+
|| ('0'..='9').contains(&ch)
28+
|| ch == '_'
29+
}
30+
31+
fn is_delimited_identifier_start(&self, ch: char) -> bool {
32+
ch == '`'
33+
}
34+
}

src/dialect/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
mod ansi;
1414
mod bigquery;
15+
mod databricks;
1516
mod generic;
1617
pub mod keywords;
1718
mod mssql;
@@ -25,6 +26,7 @@ use std::fmt::Debug;
2526

2627
pub use self::ansi::AnsiDialect;
2728
pub use self::bigquery::BigQueryDialect;
29+
pub use self::databricks::DatabricksDialect;
2830
pub use self::generic::GenericDialect;
2931
pub use self::mssql::MsSqlDialect;
3032
pub use self::mysql::MySqlDialect;

src/parser.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2072,7 +2072,10 @@ impl<'a> Parser<'a> {
20722072
// ignore the <separator> and treat the multiple strings as
20732073
// a single <literal>."
20742074
Token::SingleQuotedString(s) => Ok(Some(Ident::with_quote('\'', s))),
2075-
Token::BacktickQuotedString(s) if dialect_of!(self is BigQueryDialect) => {
2075+
Token::BacktickQuotedString(s)
2076+
if dialect_of!(self is BigQueryDialect)
2077+
|| dialect_of!(self is DatabricksDialect) =>
2078+
{
20762079
Ok(Some(Ident::with_quote('`', s)))
20772080
}
20782081
not_an_ident => {

0 commit comments

Comments
 (0)