Skip to content

Commit 9d67d0a

Browse files
committed
bq: backtick quoted idents
1 parent 4b840d2 commit 9d67d0a

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

src/parser.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2009,6 +2009,10 @@ impl<'a> Parser<'a> {
20092009
pub fn parse_identifier(&mut self) -> Result<Ident, ParserError> {
20102010
match self.next_token() {
20112011
Token::Word(w) => Ok(w.to_ident()),
2012+
Token::BacktickQuotedString(s) if dialect_of!(self is BigQueryDialect) => Ok(Ident {
2013+
value: s,
2014+
quote_style: Some('`'),
2015+
}),
20122016
unexpected => self.expected("identifier", unexpected),
20132017
}
20142018
}

src/tokenizer.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ pub enum Token {
4444
/// This should retains the escaped character sequences so that
4545
/// .to_string() of the value will give the value that was in the input
4646
SingleQuotedString(String),
47+
/// Single quoted string: i.e: 'string'
48+
BacktickQuotedString(String),
4749
/// "National" string literal: i.e: N'string'
4850
NationalStringLiteral(String),
4951
/// Hexadecimal string literal: i.e.: X'deadbeef'
@@ -159,6 +161,7 @@ impl fmt::Display for Token {
159161
Token::Number(ref n) => f.write_str(n),
160162
Token::Char(ref c) => write!(f, "{}", c),
161163
Token::SingleQuotedString(ref s) => write!(f, "'{}'", s),
164+
Token::BacktickQuotedString(ref s) => write!(f, "`{}`", s),
162165
Token::NationalStringLiteral(ref s) => write!(f, "N'{}'", s),
163166
Token::HexStringLiteral(ref s) => write!(f, "X'{}'", s),
164167
Token::Comma => f.write_str(","),
@@ -343,6 +346,7 @@ impl<'a> Tokenizer<'a> {
343346
Token::Word(w) if w.quote_style != None => self.col += w.value.len() as u64 + 2,
344347
Token::Number(s) => self.col += s.len() as u64,
345348
Token::SingleQuotedString(s) => self.col += s.len() as u64,
349+
Token::BacktickQuotedString(s) => self.col += s.len() as u64,
346350
_ => self.col += 1,
347351
}
348352

@@ -411,6 +415,18 @@ impl<'a> Tokenizer<'a> {
411415
let s = self.tokenize_single_quoted_string(chars)?;
412416
Ok(Some(Token::SingleQuotedString(s)))
413417
}
418+
// string
419+
'`' if dialect_of!(self is BigQueryDialect) => {
420+
chars.next(); // consume opening backtick
421+
let s = peeking_take_while(chars, |ch| ch != '`');
422+
match chars.peek() {
423+
Some('`') => {
424+
chars.next(); // consume closing backtick
425+
Ok(Some(Token::BacktickQuotedString(s)))
426+
}
427+
_ => self.tokenizer_error("Unterminated backtick literal"),
428+
}
429+
}
414430
// delimited (quoted) identifier
415431
quote_start if self.dialect.is_delimited_identifier_start(quote_start) => {
416432
chars.next(); // consume the opening quote

0 commit comments

Comments
 (0)