Skip to content

Commit 27e0978

Browse files
committed
fix tokenization of {{param}}._
1 parent 56bbe04 commit 27e0978

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/tokenizer.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,7 +1236,7 @@ impl<'a> Tokenizer<'a> {
12361236
// if the prev token is not a word, then this is not a valid sql
12371237
// word or number.
12381238
if ch == '.' && chars.peekable.clone().nth(1) == Some('_') {
1239-
if let Some(Token::Word(_)) = prev_token {
1239+
if let Some(Token::Word(_) | Token::Mustache(_)) = prev_token {
12401240
chars.next();
12411241
return Ok(Some(Token::Period));
12421242
}
@@ -2495,7 +2495,8 @@ fn take_char_from_hex_digits(
24952495
mod tests {
24962496
use super::*;
24972497
use crate::dialect::{
2498-
BigQueryDialect, ClickHouseDialect, HiveDialect, MsSqlDialect, MySqlDialect, SQLiteDialect,
2498+
AnsiDialect, BigQueryDialect, ClickHouseDialect, HiveDialect, MsSqlDialect, MySqlDialect,
2499+
SQLiteDialect,
24992500
};
25002501
use crate::test_utils::{all_dialects_except, all_dialects_where};
25012502
use core::fmt::Debug;
@@ -4138,4 +4139,19 @@ mod tests {
41384139
panic!("Tokenizer should have failed on {sql}, but it succeeded with {tokens:?}");
41394140
}
41404141
}
4142+
4143+
#[test]
4144+
fn tokenize_mustache_dot_ident() {
4145+
// Note: Ansi and Hive parse _column into separate `_` and `column` tokens.
4146+
all_dialects_except(|d| d.is::<HiveDialect>() || d.is::<AnsiDialect>()).tokenizes_to(
4147+
"SELECT {{schema}}._column",
4148+
vec![
4149+
Token::make_keyword("SELECT"),
4150+
Token::Whitespace(Whitespace::Space),
4151+
Token::Mustache("schema".to_owned()),
4152+
Token::Period,
4153+
Token::make_word("_column", None),
4154+
],
4155+
);
4156+
}
41414157
}

0 commit comments

Comments
 (0)