From 83aedb0efbcd8cc74097b6167a4ed418a690153d Mon Sep 17 00:00:00 2001 From: greg Date: Sun, 11 Feb 2018 16:35:38 -0800 Subject: [PATCH] Hex parsing done --- src/schala_lang/parsing.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/schala_lang/parsing.rs b/src/schala_lang/parsing.rs index 7962e7e..fc39b87 100644 --- a/src/schala_lang/parsing.rs +++ b/src/schala_lang/parsing.rs @@ -963,7 +963,9 @@ impl Parser { Ok(Expression(IntLiteral(n), None)) }, HexLiteral(text) => { - ParseError::new("Not implemented") + let digits: String = text.chars().filter(|c| c.is_digit(16)).collect(); + let n = parse_hex(digits)?; + Ok(Expression(IntLiteral(n), None)) }, _ => return ParseError::new("Expected '0x' or '0b'"), } @@ -1090,7 +1092,15 @@ mod parse_tests { fn parsing_number_literals_and_binexps() { parse_test!(".2", AST(vec![exprstatement!(FloatLiteral(0.2))])); parse_test!("8.1", AST(vec![exprstatement!(FloatLiteral(8.1))])); + parse_test!("0b010", AST(vec![exprstatement!(IntLiteral(2))])); + parse_test!("0b0_1_0_", AST(vec![exprstatement!(IntLiteral(2))])); + + parse_test!("0xff", AST(vec![exprstatement!(IntLiteral(255))])); + parse_test!("0xf_f_", AST(vec![exprstatement!(IntLiteral(255))])); + + parse_test!("0xf_f_+1", AST(vec![exprstatement!(binexp!("+", IntLiteral(255), IntLiteral(1)))])); + parse_test!("3; 4; 4.3", AST( vec![exprstatement!(IntLiteral(3)), exprstatement!(IntLiteral(4)), exprstatement!(FloatLiteral(4.3))]));