diff options
| author | Laurenz <laurmaedje@gmail.com> | 2023-04-04 15:22:48 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2023-04-04 15:46:09 +0200 |
| commit | 570c528b3e4e41af2bb8ec0cf091e52dd50db13a (patch) | |
| tree | 02ed402ad10741ae70fb9dab03ce735d35eac2a8 /src/syntax/ast.rs | |
| parent | f738d89ff2de20f3293a8e413160b7ab48cf593a (diff) | |
Integers with different bases
Diffstat (limited to 'src/syntax/ast.rs')
| -rw-r--r-- | src/syntax/ast.rs | 12 |
1 files changed, 11 insertions, 1 deletions
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() } } |
