From 570c528b3e4e41af2bb8ec0cf091e52dd50db13a Mon Sep 17 00:00:00 2001 From: Laurenz Date: Tue, 4 Apr 2023 15:22:48 +0200 Subject: Integers with different bases --- src/syntax/ast.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/syntax/ast.rs') diff --git a/src/syntax/ast.rs b/src/syntax/ast.rs index 4abf51d9..d718ccf0 100644 --- a/src/syntax/ast.rs +++ b/src/syntax/ast.rs @@ -912,7 +912,17 @@ node! { impl Int { /// Get the integer value. pub fn get(&self) -> i64 { - self.0.text().parse().unwrap_or_default() + let text = self.0.text(); + if let Some(rest) = text.strip_prefix("0x") { + i64::from_str_radix(rest, 16) + } else if let Some(rest) = text.strip_prefix("0o") { + i64::from_str_radix(rest, 8) + } else if let Some(rest) = text.strip_prefix("0b") { + i64::from_str_radix(rest, 2) + } else { + text.parse() + } + .unwrap_or_default() } } -- cgit v1.2.3