Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse integer suffix beginning with a hex digit #252

Merged
merged 2 commits into from
Sep 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -648,10 +648,25 @@ fn digits(mut input: Cursor) -> Result<Cursor, LexError> {
let mut len = 0;
let mut empty = true;
for b in input.bytes() {
let digit = match b {
b'0'..=b'9' => (b - b'0') as u64,
b'a'..=b'f' => 10 + (b - b'a') as u64,
b'A'..=b'F' => 10 + (b - b'A') as u64,
match b {
b'0'..=b'9' => {
let digit = (b - b'0') as u64;
if digit >= base {
return Err(LexError);
}
}
b'a'..=b'f' => {
let digit = 10 + (b - b'a') as u64;
if digit >= base {
break;
}
}
b'A'..=b'F' => {
let digit = 10 + (b - b'A') as u64;
if digit >= base {
break;
}
}
b'_' => {
if empty && base == 10 {
return Err(LexError);
Expand All @@ -661,9 +676,6 @@ fn digits(mut input: Cursor) -> Result<Cursor, LexError> {
}
_ => break,
};
if digit >= base {
return Err(LexError);
}
len += 1;
empty = false;
}
Expand Down
2 changes: 2 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ fn literal_suffix() {
assert_eq!(token_count("r#\"\"#r"), 1);
assert_eq!(token_count("'c'c"), 1);
assert_eq!(token_count("b'b'b"), 1);
assert_eq!(token_count("0E"), 1);
assert_eq!(token_count("0o0A"), 1);
}

#[test]
Expand Down