mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-31 11:17:23 +00:00
Support Parsing of hexadecimal literals that start with 0x (#324)
* Add support for 0x prefixed bin literal * Add tests * Fix formatting for test
This commit is contained in:
parent
a95c81fb13
commit
70ffa4166c
2 changed files with 16 additions and 0 deletions
|
@ -417,6 +417,17 @@ impl<'a> Tokenizer<'a> {
|
|||
// numbers and period
|
||||
'0'..='9' | '.' => {
|
||||
let mut s = peeking_take_while(chars, |ch| matches!(ch, '0'..='9'));
|
||||
|
||||
// match binary literal that starts with 0x
|
||||
if s == "0" && chars.peek() == Some(&'x') {
|
||||
chars.next();
|
||||
let s2 = peeking_take_while(
|
||||
chars,
|
||||
|ch| matches!(ch, '0'..='9' | 'A'..='F' | 'a'..='f'),
|
||||
);
|
||||
return Ok(Some(Token::HexStringLiteral(s2)));
|
||||
}
|
||||
|
||||
// match one period
|
||||
if let Some('.') = chars.peek() {
|
||||
s.push('.');
|
||||
|
|
|
@ -113,6 +113,11 @@ fn parse_mssql_top() {
|
|||
let _ = ms_and_generic().one_statement_parses_to(sql, "SELECT TOP (5) bar, baz FROM foo");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_mssql_bin_literal() {
|
||||
let _ = ms_and_generic().one_statement_parses_to("SELECT 0xdeadBEEF", "SELECT X'deadBEEF'");
|
||||
}
|
||||
|
||||
fn ms() -> TestedDialects {
|
||||
TestedDialects {
|
||||
dialects: vec![Box::new(MsSqlDialect {})],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue