Skip to content

Commit

Permalink
Support number format with underscore between digits
Browse files Browse the repository at this point in the history
  • Loading branch information
AmrDeveloper committed Jul 10, 2023
1 parent 4701290 commit edb6197
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/tokenizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -503,12 +503,14 @@ fn consume_identifier(chars: &Vec<char>, pos: &mut usize, start: &mut usize) ->
}

fn consume_number(chars: &Vec<char>, pos: &mut usize, start: &mut usize) -> Token {
while *pos < chars.len() && chars[*pos].is_numeric() {
while *pos < chars.len() && (chars[*pos].is_numeric() || chars[*pos] == '_') {
*pos += 1;
}

let literal = &chars[*start..*pos];
let string = String::from_utf8(literal.iter().map(|&c| c as u8).collect()).unwrap();
let literal_num = string.to_string().replace("_", "");
println!("Number after {}", literal_num);

let location = Location {
start: *start,
Expand All @@ -518,7 +520,7 @@ fn consume_number(chars: &Vec<char>, pos: &mut usize, start: &mut usize) -> Toke
return Token {
location,
kind: TokenKind::Number,
literal: string.to_string(),
literal: literal_num,
};
}

Expand Down

0 comments on commit edb6197

Please sign in to comment.