Skip to content

Commit 4b840d2

Browse files
committed
add BigQueryDialect
1 parent 2f8dfb4 commit 4b840d2

3 files changed

Lines changed: 35 additions & 2 deletions

File tree

src/dialect/bigquery.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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, Default)]
16+
pub struct BigQueryDialect;
17+
18+
impl Dialect for BigQueryDialect {
19+
// see https://cloud.google.com/bigquery/docs/reference/standard-sql/lexical#identifiers
20+
fn is_identifier_start(&self, ch: char) -> bool {
21+
(ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || ch == '_'
22+
}
23+
24+
fn is_identifier_part(&self, ch: char) -> bool {
25+
(ch >= 'a' && ch <= 'z')
26+
|| (ch >= 'A' && ch <= 'Z')
27+
|| (ch >= '0' && ch <= '9')
28+
|| ch == '_'
29+
}
30+
}

src/dialect/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
// limitations under the License.
1212

1313
mod ansi;
14+
mod bigquery;
1415
mod generic;
1516
pub mod keywords;
1617
mod mssql;
@@ -23,6 +24,7 @@ use std::any::{Any, TypeId};
2324
use std::fmt::Debug;
2425

2526
pub use self::ansi::AnsiDialect;
27+
pub use self::bigquery::BigQueryDialect;
2628
pub use self::generic::GenericDialect;
2729
pub use self::mssql::MsSqlDialect;
2830
pub use self::mysql::MySqlDialect;

src/tokenizer.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use std::iter::Peekable;
2020
use std::str::Chars;
2121

2222
use super::dialect::keywords::{Keyword, ALL_KEYWORDS, ALL_KEYWORDS_INDEX};
23+
use super::dialect::BigQueryDialect;
2324
use super::dialect::Dialect;
2425
use super::dialect::PostgreSqlDialect;
2526
use super::dialect::SnowflakeDialect;
@@ -465,7 +466,7 @@ impl<'a> Tokenizer<'a> {
465466
chars.next(); // consume the '*', starting a multi-line comment
466467
self.tokenize_multiline_comment(chars)
467468
}
468-
Some('/') if dialect_of!(self is SnowflakeDialect) => {
469+
Some('/') if dialect_of!(self is SnowflakeDialect | BigQueryDialect) => {
469470
chars.next(); // consume the second '/', starting a snowflake single-line comment
470471
let comment = self.tokenize_single_line_comment(chars);
471472
Ok(Some(Token::Whitespace(Whitespace::SingleLineComment {
@@ -542,7 +543,7 @@ impl<'a> Tokenizer<'a> {
542543
'^' => self.consume_and_return(chars, Token::Caret),
543544
'{' => self.consume_and_return(chars, Token::LBrace),
544545
'}' => self.consume_and_return(chars, Token::RBrace),
545-
'#' if dialect_of!(self is SnowflakeDialect) => {
546+
'#' if dialect_of!(self is SnowflakeDialect | BigQueryDialect) => {
546547
chars.next(); // consume the '#', starting a snowflake single-line comment
547548
let comment = self.tokenize_single_line_comment(chars);
548549
Ok(Some(Token::Whitespace(Whitespace::SingleLineComment {

0 commit comments

Comments
 (0)