From 63bc5fa1dbd38782e78fa13745eec64b41ca9ca4 Mon Sep 17 00:00:00 2001 From: Mees Delzenne Date: Fri, 16 Aug 2024 15:59:59 +0200 Subject: [PATCH] Fix certain identifier characters not being parsed correctly (#4522) --- core/src/syn/parser/test/mod.rs | 36 ++++++++++++++++++++++++++++++++- core/src/syn/parser/token.rs | 13 ++++++------ 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/core/src/syn/parser/test/mod.rs b/core/src/syn/parser/test/mod.rs index b7e89d36..a5693e25 100644 --- a/core/src/syn/parser/test/mod.rs +++ b/core/src/syn/parser/test/mod.rs @@ -1,6 +1,9 @@ use nom::AsBytes; -use crate::{sql, syn::parser::mac::test_parse}; +use crate::{ + sql::{self, Id, Statement, Thing, Value}, + syn::parser::mac::test_parse, +}; mod limit; mod stmt; @@ -14,6 +17,37 @@ fn multiple_semicolons() { assert_eq!(res, expected); } +#[test] +fn glued_identifiers() { + let res = test_parse!(parse_query, r#"T:1"#).unwrap(); + let expected = sql::Query(sql::Statements(vec![Statement::Value(Value::Thing(Thing { + tb: "T".to_string(), + id: Id::Number(1), + }))])); + assert_eq!(res, expected); + + let res = test_parse!(parse_query, r#"T9T9T9T:1"#).unwrap(); + let expected = sql::Query(sql::Statements(vec![Statement::Value(Value::Thing(Thing { + tb: "T9T9T9T".to_string(), + id: Id::Number(1), + }))])); + assert_eq!(res, expected); + + let res = test_parse!(parse_query, r#"Z:1"#).unwrap(); + let expected = sql::Query(sql::Statements(vec![Statement::Value(Value::Thing(Thing { + tb: "Z".to_string(), + id: Id::Number(1), + }))])); + assert_eq!(res, expected); + + let res = test_parse!(parse_query, r#"Z9Z9Z9Z:1"#).unwrap(); + let expected = sql::Query(sql::Statements(vec![Statement::Value(Value::Thing(Thing { + tb: "Z9Z9Z9Z".to_string(), + id: Id::Number(1), + }))])); + assert_eq!(res, expected); +} + #[test] fn escaped_params() { let src = r#"LET $⟨R-_fYU8Wa31kg7tz0JI6Kme⟩ = 5; diff --git a/core/src/syn/parser/token.rs b/core/src/syn/parser/token.rs index 0ba4ab40..962a9ff3 100644 --- a/core/src/syn/parser/token.rs +++ b/core/src/syn/parser/token.rs @@ -128,6 +128,11 @@ impl Parser<'_> { self.span_str(start.span).to_owned() } + TokenKind::DatetimeChars(_) => { + self.pop_peek(); + + self.span_str(start.span).to_owned() + } _ => return Ok(start), }; @@ -168,7 +173,7 @@ impl Parser<'_> { break; } // These tokens might have some more parts following them - TokenKind::Exponent => { + TokenKind::Exponent | TokenKind::DatetimeChars(_) | TokenKind::Digits => { self.pop_peek(); let str = self.span_str(p.span); token_buffer.push_str(str); @@ -183,12 +188,6 @@ impl Parser<'_> { token_buffer.push_str(suffix.as_str()); prev = p; } - TokenKind::Digits => { - self.pop_peek(); - let str = self.span_str(p.span); - token_buffer.push_str(str); - prev = p; - } _ => break, } }