Skip to content

Commit 36b8847

Browse files
authored
Fix tokenization of {{mustache}}._ident (#41)
2 parents 56bbe04 + a999297 commit 36b8847

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

src/ast/mod.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2732,10 +2732,11 @@ impl fmt::Display for Declare {
27322732
}
27332733

27342734
/// Sql options of a `CREATE TABLE` statement.
2735-
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2735+
#[derive(Default, Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
27362736
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
27372737
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
27382738
pub enum CreateTableOptions {
2739+
#[default]
27392740
None,
27402741
/// Options specified using the `WITH` keyword.
27412742
/// e.g. `WITH (description = "123")`
@@ -2764,12 +2765,6 @@ pub enum CreateTableOptions {
27642765
TableProperties(Vec<SqlOption>),
27652766
}
27662767

2767-
impl Default for CreateTableOptions {
2768-
fn default() -> Self {
2769-
Self::None
2770-
}
2771-
}
2772-
27732768
impl fmt::Display for CreateTableOptions {
27742769
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
27752770
match self {

src/tokenizer.rs

Lines changed: 15 additions & 1 deletion
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
}
@@ -4138,4 +4138,18 @@ mod tests {
41384138
panic!("Tokenizer should have failed on {sql}, but it succeeded with {tokens:?}");
41394139
}
41404140
}
4141+
4142+
#[test]
4143+
fn tokenize_mustache_dot_ident() {
4144+
all_dialects_where(|d| d.is_identifier_start('_')).tokenizes_to(
4145+
"SELECT {{schema}}._column",
4146+
vec![
4147+
Token::make_keyword("SELECT"),
4148+
Token::Whitespace(Whitespace::Space),
4149+
Token::Mustache("schema".to_owned()),
4150+
Token::Period,
4151+
Token::make_word("_column", None),
4152+
],
4153+
);
4154+
}
41414155
}

0 commit comments

Comments
 (0)