Starting hex parsing
This commit is contained in:
parent
bec8aedc22
commit
30a6d0929a
@ -1003,6 +1003,19 @@ fn parse_binary(digits: String) -> ParseResult<u64> {
|
|||||||
Ok(result)
|
Ok(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn parse_hex(digits: String) -> ParseResult<u64> {
|
||||||
|
let mut result: u64 = 0;
|
||||||
|
let mut multiplier: u64 = 1;
|
||||||
|
for d in digits.chars().rev() {
|
||||||
|
match d.to_digit(16) {
|
||||||
|
Some(n) => result += n as u64 * multiplier,
|
||||||
|
None => return ParseError::new("Encountered a non-hex digit in a hex literal"),
|
||||||
|
}
|
||||||
|
multiplier *= 16;
|
||||||
|
}
|
||||||
|
Ok(result)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn parse(input: Vec<Token>) -> (Result<AST, ParseError>, Vec<String>) {
|
pub fn parse(input: Vec<Token>) -> (Result<AST, ParseError>, Vec<String>) {
|
||||||
let mut parser = Parser::new(input);
|
let mut parser = Parser::new(input);
|
||||||
let ast = parser.program();
|
let ast = parser.program();
|
||||||
|
Loading…
Reference in New Issue
Block a user