Fix certain identifier characters not being parsed correctly (#4522)

This commit is contained in:
Mees Delzenne 2024-08-16 15:59:59 +02:00 committed by GitHub
parent 6e9d04d4d7
commit 63bc5fa1db
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 41 additions and 8 deletions

View file

@ -1,6 +1,9 @@
use nom::AsBytes; 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 limit;
mod stmt; mod stmt;
@ -14,6 +17,37 @@ fn multiple_semicolons() {
assert_eq!(res, expected); 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] #[test]
fn escaped_params() { fn escaped_params() {
let src = r#"LET $⟨R-_fYU8Wa31kg7tz0JI6Kme⟩ = 5; let src = r#"LET $⟨R-_fYU8Wa31kg7tz0JI6Kme⟩ = 5;

View file

@ -128,6 +128,11 @@ impl Parser<'_> {
self.span_str(start.span).to_owned() self.span_str(start.span).to_owned()
} }
TokenKind::DatetimeChars(_) => {
self.pop_peek();
self.span_str(start.span).to_owned()
}
_ => return Ok(start), _ => return Ok(start),
}; };
@ -168,7 +173,7 @@ impl Parser<'_> {
break; break;
} }
// These tokens might have some more parts following them // These tokens might have some more parts following them
TokenKind::Exponent => { TokenKind::Exponent | TokenKind::DatetimeChars(_) | TokenKind::Digits => {
self.pop_peek(); self.pop_peek();
let str = self.span_str(p.span); let str = self.span_str(p.span);
token_buffer.push_str(str); token_buffer.push_str(str);
@ -183,12 +188,6 @@ impl Parser<'_> {
token_buffer.push_str(suffix.as_str()); token_buffer.push_str(suffix.as_str());
prev = p; prev = p;
} }
TokenKind::Digits => {
self.pop_peek();
let str = self.span_str(p.span);
token_buffer.push_str(str);
prev = p;
}
_ => break, _ => break,
} }
} }