Adopt the new hex float parsing

This eliminates hexponent.
This commit is contained in:
ridiculousfish 2024-05-25 17:20:08 -04:00
parent bed2ff2ea6
commit 08f8983085
4 changed files with 8 additions and 26 deletions

6
Cargo.lock generated
View file

@ -102,7 +102,6 @@ dependencies = [
"cc", "cc",
"errno", "errno",
"fast-float", "fast-float",
"hexponent",
"lazy_static", "lazy_static",
"libc", "libc",
"lru", "lru",
@ -151,11 +150,6 @@ version = "0.14.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1"
[[package]]
name = "hexponent"
version = "0.3.1"
source = "git+https://github.com/fish-shell/hexponent?branch=fish#71febaf2ffa3c63ea50a70aa4308293d69bd709c"
[[package]] [[package]]
name = "itertools" name = "itertools"
version = "0.9.0" version = "0.9.0"

View file

@ -21,7 +21,6 @@ default-run = "fish"
[dependencies] [dependencies]
pcre2 = { git = "https://github.com/fish-shell/rust-pcre2", branch = "master", default-features = false, features = ["utf32"] } pcre2 = { git = "https://github.com/fish-shell/rust-pcre2", branch = "master", default-features = false, features = ["utf32"] }
fast-float = { git = "https://github.com/fish-shell/fast-float-rust", branch="fish" } fast-float = { git = "https://github.com/fish-shell/fast-float-rust", branch="fish" }
hexponent = { git = "https://github.com/fish-shell/hexponent", branch="fish" }
printf-compat = { git = "https://github.com/fish-shell/printf-compat.git", branch="fish" } printf-compat = { git = "https://github.com/fish-shell/printf-compat.git", branch="fish" }
bitflags = "2.4.0" bitflags = "2.4.0"

View file

@ -45,7 +45,6 @@ pub struct SyntaxError;
/// A `Result` containing either: /// A `Result` containing either:
/// - A tuple of the parsed floating-point number (`f64`) and the number of characters consumed (`usize`), or /// - A tuple of the parsed floating-point number (`f64`) and the number of characters consumed (`usize`), or
/// - A `SyntaxError` if the parsing fails. /// - A `SyntaxError` if the parsing fails.
#[allow(dead_code)]
pub fn parse_hex_float( pub fn parse_hex_float(
chars: impl Iterator<Item = char>, chars: impl Iterator<Item = char>,
decimal_sep: char, decimal_sep: char,

View file

@ -1,4 +1,5 @@
use super::errors::Error; use super::errors::Error;
use super::hex_float;
use crate::wchar::IntoCharIter; use crate::wchar::IntoCharIter;
use fast_float::parse_partial_iter; use fast_float::parse_partial_iter;
@ -22,14 +23,14 @@ where
} }
} }
// If it's a hex float, use hexponent. // If it's a hex float, parse it.
if is_hex_float(chars.clone()) { if is_hex_float(chars.clone()) {
let mut n = 0; return if let Ok((f, amt)) = hex_float::parse_hex_float(chars, decimal_sep) {
let res = hexponent::parse_hex_float(chars, decimal_sep, &mut n); *consumed = whitespace_skipped + amt;
if res.is_ok() { Ok(f)
*consumed = whitespace_skipped + n; } else {
} Err(Error::InvalidChar)
return res.map_err(hexponent_error); };
} }
let ret = parse_partial_iter(chars.clone().fuse(), decimal_sep); let ret = parse_partial_iter(chars.clone().fuse(), decimal_sep);
@ -100,17 +101,6 @@ pub fn is_hex_float<Chars: Iterator<Item = char>>(mut chars: Chars) -> bool {
} }
} }
// Convert a a hexponent error to our error type.
fn hexponent_error(e: hexponent::ParseError) -> Error {
use hexponent::ParseErrorKind;
match e.kind {
ParseErrorKind::MissingPrefix
| ParseErrorKind::MissingDigits
| ParseErrorKind::MissingExponent => Error::InvalidChar,
ParseErrorKind::ExponentOverflow => Error::Overflow,
}
}
/// Like [`wcstod()`], but allows underscore separators. Leading, trailing, and multiple underscores /// Like [`wcstod()`], but allows underscore separators. Leading, trailing, and multiple underscores
/// are allowed, as are underscores next to decimal (`.`), exponent (`E`/`e`/`P`/`p`), and /// are allowed, as are underscores next to decimal (`.`), exponent (`E`/`e`/`P`/`p`), and
/// hexadecimal (`X`/`x`) delimiters. This consumes trailing underscores -- `consumed` will include /// hexadecimal (`X`/`x`) delimiters. This consumes trailing underscores -- `consumed` will include