Skip to content

Commit dd733bf

Browse files
committed
bq: double quoted string
1 parent 4b4fb62 commit dd733bf

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

src/ast/value.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ pub enum Value {
2727
Number(BigDecimal),
2828
/// 'string value'
2929
SingleQuotedString(String),
30+
/// "string value"
31+
DoubleQuotedString(String),
3032
/// r'string value'
3133
RegexLiteral { value: String, quote: char },
3234
/// N'string value'
@@ -63,7 +65,8 @@ impl fmt::Display for Value {
6365
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6466
match self {
6567
Value::Number(v) => write!(f, "{}", v),
66-
Value::SingleQuotedString(v) => write!(f, "'{}'", escape_single_quote_string(v)),
68+
Value::SingleQuotedString(v) => write!(f, "'{}'", v),
69+
Value::DoubleQuotedString(v) => write!(f, "\"{}\"", v),
6770
Value::RegexLiteral { ref value, quote } => write!(f, "{}{}{}", quote, value, quote),
6871
Value::NationalStringLiteral(v) => write!(f, "N'{}'", v),
6972
Value::HexStringLiteral(v) => write!(f, "X'{}'", v),

src/parser.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ impl<'a> Parser<'a> {
276276
value: w.clone(),
277277
quote_style: Some('`'),
278278
}),
279+
Token::DoubleQuotedString(s) => Ok(Expr::Value(Value::DoubleQuotedString(s))),
279280
Token::BqRegexQuotedString { value, quote } => {
280281
Ok(Expr::Value(Value::RegexLiteral { value, quote }))
281282
}

src/tokenizer.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ 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+
/// Double quoted string: i.e: "string"
48+
/// This should retains the escaped character sequences so that
49+
/// .to_string() of the value will give the value that was in the input
50+
DoubleQuotedString(String),
4751
/// Single quoted string: i.e: 'string'
4852
BacktickQuotedString(String),
4953
BqRegexQuotedString {
@@ -165,6 +169,7 @@ impl fmt::Display for Token {
165169
Token::Number(ref n) => f.write_str(n),
166170
Token::Char(ref c) => write!(f, "{}", c),
167171
Token::SingleQuotedString(ref s) => write!(f, "'{}'", s),
172+
Token::DoubleQuotedString(ref s) => write!(f, "\"{}\"", s),
168173
Token::BacktickQuotedString(ref s) => write!(f, "`{}`", s),
169174
Token::NationalStringLiteral(ref s) => write!(f, "N'{}'", s),
170175
Token::BqRegexQuotedString { ref value, quote } => {
@@ -353,6 +358,7 @@ impl<'a> Tokenizer<'a> {
353358
Token::Word(w) if w.quote_style != None => self.col += w.value.len() as u64 + 2,
354359
Token::Number(s) => self.col += s.len() as u64,
355360
Token::SingleQuotedString(s) => self.col += s.len() as u64,
361+
Token::DoubleQuotedString(s) => self.col += s.len() as u64,
356362
Token::BacktickQuotedString(s) => self.col += s.len() as u64,
357363
_ => self.col += 1,
358364
}
@@ -443,6 +449,11 @@ impl<'a> Tokenizer<'a> {
443449
Ok(Some(Token::SingleQuotedString(s)))
444450
}
445451
// string
452+
'"' if dialect_of!(self is BigQueryDialect) => {
453+
let s = self.tokenize_double_quoted_string(chars)?;
454+
Ok(Some(Token::DoubleQuotedString(s)))
455+
}
456+
// string
446457
'`' if dialect_of!(self is BigQueryDialect) => {
447458
chars.next(); // consume opening backtick
448459
let s = peeking_take_while(chars, |ch| ch != '`');

0 commit comments

Comments
 (0)