Skip to content

Commit 70ffa41

Browse files
authored
Support Parsing of hexadecimal literals that start with 0x (apache#324)
* Add support for 0x prefixed bin literal * Add tests * Fix formatting for test
1 parent a95c81f commit 70ffa41

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/tokenizer.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,17 @@ impl<'a> Tokenizer<'a> {
417417
// numbers and period
418418
'0'..='9' | '.' => {
419419
let mut s = peeking_take_while(chars, |ch| matches!(ch, '0'..='9'));
420+
421+
// match binary literal that starts with 0x
422+
if s == "0" && chars.peek() == Some(&'x') {
423+
chars.next();
424+
let s2 = peeking_take_while(
425+
chars,
426+
|ch| matches!(ch, '0'..='9' | 'A'..='F' | 'a'..='f'),
427+
);
428+
return Ok(Some(Token::HexStringLiteral(s2)));
429+
}
430+
420431
// match one period
421432
if let Some('.') = chars.peek() {
422433
s.push('.');

tests/sqlparser_mssql.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ fn parse_mssql_top() {
113113
let _ = ms_and_generic().one_statement_parses_to(sql, "SELECT TOP (5) bar, baz FROM foo");
114114
}
115115

116+
#[test]
117+
fn parse_mssql_bin_literal() {
118+
let _ = ms_and_generic().one_statement_parses_to("SELECT 0xdeadBEEF", "SELECT X'deadBEEF'");
119+
}
120+
116121
fn ms() -> TestedDialects {
117122
TestedDialects {
118123
dialects: vec![Box::new(MsSqlDialect {})],

0 commit comments

Comments
 (0)