Skip underscore in fraction indexes

This commit is contained in:
imaqtkatt 2024-08-05 08:57:18 -03:00
parent 6e56b63e83
commit 96d84d5257
3 changed files with 7 additions and 5 deletions

View File

@ -1572,8 +1572,10 @@ pub trait ParserCommons<'a>: Parser<'a> {
let frac = if let Some('.') = self.peek_one() {
self.advance_one();
let ini_idx = *self.index();
let fra = self.u32_with_radix(radix)?;
let end_idx = *self.index();
let fra_str = self.take_while(|c| c.is_digit(radix as u32) || c == '_');
let fra_str = fra_str.chars().filter(|c| *c != '_').collect::<String>();
let end_idx = ini_idx + fra_str.len();
let fra = u32::from_str_radix(&fra_str, radix as u32).map_err(|e| e.to_string())?;
let fra = fra as f32 / (radix.to_f32()).powi((end_idx - ini_idx) as i32);
Some(fra)
} else {

View File

@ -1,2 +1,2 @@
def main:
return [0x12.129, 0x0.2, 0b101.101, 0xAAAAAAAA.AAAAAAAA]
return [0x12.129, 0x0.2, 0b101.101, 0xAAAAAAAA.AAAAAAAA, 0xA.__A__]

View File

@ -3,7 +3,7 @@ source: tests/golden_tests.rs
input_file: tests/golden_tests/run_file/floating_numbers.bend
---
NumScott:
[18.072, 0.125, 5.625, 2863333376.000]
[18.072, 0.125, 5.625, 2863333376.000, 10.625]
Scott:
[18.072, 0.125, 5.625, 2863333376.000]
[18.072, 0.125, 5.625, 2863333376.000, 10.625]