mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 12:53:13 +00:00
Adopt the new hex float parsing
This eliminates hexponent.
This commit is contained in:
parent
bed2ff2ea6
commit
08f8983085
4 changed files with 8 additions and 26 deletions
6
Cargo.lock
generated
6
Cargo.lock
generated
|
@ -102,7 +102,6 @@ dependencies = [
|
|||
"cc",
|
||||
"errno",
|
||||
"fast-float",
|
||||
"hexponent",
|
||||
"lazy_static",
|
||||
"libc",
|
||||
"lru",
|
||||
|
@ -151,11 +150,6 @@ version = "0.14.5"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1"
|
||||
|
||||
[[package]]
|
||||
name = "hexponent"
|
||||
version = "0.3.1"
|
||||
source = "git+https://github.com/fish-shell/hexponent?branch=fish#71febaf2ffa3c63ea50a70aa4308293d69bd709c"
|
||||
|
||||
[[package]]
|
||||
name = "itertools"
|
||||
version = "0.9.0"
|
||||
|
|
|
@ -21,7 +21,6 @@ default-run = "fish"
|
|||
[dependencies]
|
||||
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" }
|
||||
hexponent = { git = "https://github.com/fish-shell/hexponent", branch="fish" }
|
||||
printf-compat = { git = "https://github.com/fish-shell/printf-compat.git", branch="fish" }
|
||||
|
||||
bitflags = "2.4.0"
|
||||
|
|
|
@ -45,7 +45,6 @@ pub struct SyntaxError;
|
|||
/// A `Result` containing either:
|
||||
/// - A tuple of the parsed floating-point number (`f64`) and the number of characters consumed (`usize`), or
|
||||
/// - A `SyntaxError` if the parsing fails.
|
||||
#[allow(dead_code)]
|
||||
pub fn parse_hex_float(
|
||||
chars: impl Iterator<Item = char>,
|
||||
decimal_sep: char,
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use super::errors::Error;
|
||||
use super::hex_float;
|
||||
use crate::wchar::IntoCharIter;
|
||||
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()) {
|
||||
let mut n = 0;
|
||||
let res = hexponent::parse_hex_float(chars, decimal_sep, &mut n);
|
||||
if res.is_ok() {
|
||||
*consumed = whitespace_skipped + n;
|
||||
}
|
||||
return res.map_err(hexponent_error);
|
||||
return if let Ok((f, amt)) = hex_float::parse_hex_float(chars, decimal_sep) {
|
||||
*consumed = whitespace_skipped + amt;
|
||||
Ok(f)
|
||||
} else {
|
||||
Err(Error::InvalidChar)
|
||||
};
|
||||
}
|
||||
|
||||
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
|
||||
/// 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
|
||||
|
|
Loading…
Reference in a new issue