Skip to content

Commit

Permalink
Merge pull request #252 from dtolnay/lit
Browse files Browse the repository at this point in the history
Parse integer suffix beginning with a hex digit
  • Loading branch information
dtolnay committed Sep 25, 2020
2 parents 285269e + 1412125 commit ac910cf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
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

0 comments on commit ac910cf

Please sign in to comment.