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:
TheSchemm 2021-08-25 11:57:32 -05:00 committed by GitHub
parent a95c81fb13
commit 70ffa4166c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 0 deletions

View file

@ -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('.');

View file

@ -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 {})],