diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-18 02:49:42 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-18 02:49:42 +0000 |
commit | 837b550238aa671a591ccf282dddeab29cadb206 (patch) | |
tree | 914b6b8862bace72bd3245ca184d374b08d8a672 /vendor/nom/src/number | |
parent | Adding debian version 1.70.0+dfsg2-1. (diff) | |
download | rustc-837b550238aa671a591ccf282dddeab29cadb206.tar.xz rustc-837b550238aa671a591ccf282dddeab29cadb206.zip |
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/nom/src/number')
-rw-r--r-- | vendor/nom/src/number/complete.rs | 91 | ||||
-rw-r--r-- | vendor/nom/src/number/streaming.rs | 89 |
2 files changed, 73 insertions, 107 deletions
diff --git a/vendor/nom/src/number/complete.rs b/vendor/nom/src/number/complete.rs index d23079e76..98b8b3abf 100644 --- a/vendor/nom/src/number/complete.rs +++ b/vendor/nom/src/number/complete.rs @@ -13,26 +13,6 @@ use crate::traits::{ AsBytes, AsChar, Compare, InputIter, InputLength, InputTake, InputTakeAtPosition, Offset, Slice, }; -#[doc(hidden)] -macro_rules! map( - // Internal parser, do not use directly - (__impl $i:expr, $submac:ident!( $($args:tt)* ), $g:expr) => ( - $crate::combinator::map(move |i| {$submac!(i, $($args)*)}, $g).parse($i) - ); - ($i:expr, $submac:ident!( $($args:tt)* ), $g:expr) => ( - map!(__impl $i, $submac!($($args)*), $g) - ); - ($i:expr, $f:expr, $g:expr) => ( - map!(__impl $i, call!($f), $g) - ); -); - -#[doc(hidden)] -macro_rules! call ( - ($i:expr, $fun:expr) => ( $fun( $i ) ); - ($i:expr, $fun:expr, $($args:expr),* ) => ( $fun( $i, $($args),* ) ); -); - /// Recognizes an unsigned 1 byte integer. /// /// *Complete version*: Returns an error if there is not enough input data. @@ -211,7 +191,6 @@ where /// assert_eq!(parser(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof)))); /// ``` #[inline] -#[cfg(stable_i128)] pub fn be_u128<I, E: ParseError<I>>(input: I) -> IResult<I, u128, E> where I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength, @@ -249,7 +228,7 @@ pub fn be_i8<I, E: ParseError<I>>(input: I) -> IResult<I, i8, E> where I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength, { - map!(input, be_u8, |x| x as i8) + be_u8.map(|x| x as i8).parse(input) } /// Recognizes a big endian signed 2 bytes integer. @@ -272,7 +251,7 @@ pub fn be_i16<I, E: ParseError<I>>(input: I) -> IResult<I, i16, E> where I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength, { - map!(input, be_u16, |x| x as i16) + be_u16.map(|x| x as i16).parse(input) } /// Recognizes a big endian signed 3 bytes integer. @@ -296,16 +275,20 @@ where I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength, { // Same as the unsigned version but we need to sign-extend manually here - map!(input, be_u24, |x| if x & 0x80_00_00 != 0 { - (x | 0xff_00_00_00) as i32 - } else { - x as i32 - }) + be_u24 + .map(|x| { + if x & 0x80_00_00 != 0 { + (x | 0xff_00_00_00) as i32 + } else { + x as i32 + } + }) + .parse(input) } /// Recognizes a big endian signed 4 bytes integer. /// -/// *Complete version*: Teturns an error if there is not enough input data. +/// *Complete version*: Returns an error if there is not enough input data. /// ```rust /// # use nom::{Err, error::ErrorKind, Needed}; /// # use nom::Needed::Size; @@ -323,7 +306,7 @@ pub fn be_i32<I, E: ParseError<I>>(input: I) -> IResult<I, i32, E> where I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength, { - map!(input, be_u32, |x| x as i32) + be_u32.map(|x| x as i32).parse(input) } /// Recognizes a big endian signed 8 bytes integer. @@ -346,7 +329,7 @@ pub fn be_i64<I, E: ParseError<I>>(input: I) -> IResult<I, i64, E> where I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength, { - map!(input, be_u64, |x| x as i64) + be_u64.map(|x| x as i64).parse(input) } /// Recognizes a big endian signed 16 bytes integer. @@ -365,12 +348,11 @@ where /// assert_eq!(parser(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof)))); /// ``` #[inline] -#[cfg(stable_i128)] pub fn be_i128<I, E: ParseError<I>>(input: I) -> IResult<I, i128, E> where I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength, { - map!(input, be_u128, |x| x as i128) + be_u128.map(|x| x as i128).parse(input) } /// Recognizes an unsigned 1 byte integer. @@ -551,7 +533,6 @@ where /// assert_eq!(parser(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof)))); /// ``` #[inline] -#[cfg(stable_i128)] pub fn le_u128<I, E: ParseError<I>>(input: I) -> IResult<I, u128, E> where I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength, @@ -589,7 +570,7 @@ pub fn le_i8<I, E: ParseError<I>>(input: I) -> IResult<I, i8, E> where I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength, { - map!(input, be_u8, |x| x as i8) + be_u8.map(|x| x as i8).parse(input) } /// Recognizes a little endian signed 2 bytes integer. @@ -612,7 +593,7 @@ pub fn le_i16<I, E: ParseError<I>>(input: I) -> IResult<I, i16, E> where I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength, { - map!(input, le_u16, |x| x as i16) + le_u16.map(|x| x as i16).parse(input) } /// Recognizes a little endian signed 3 bytes integer. @@ -636,11 +617,15 @@ where I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength, { // Same as the unsigned version but we need to sign-extend manually here - map!(input, le_u24, |x| if x & 0x80_00_00 != 0 { - (x | 0xff_00_00_00) as i32 - } else { - x as i32 - }) + le_u24 + .map(|x| { + if x & 0x80_00_00 != 0 { + (x | 0xff_00_00_00) as i32 + } else { + x as i32 + } + }) + .parse(input) } /// Recognizes a little endian signed 4 bytes integer. @@ -663,7 +648,7 @@ pub fn le_i32<I, E: ParseError<I>>(input: I) -> IResult<I, i32, E> where I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength, { - map!(input, le_u32, |x| x as i32) + le_u32.map(|x| x as i32).parse(input) } /// Recognizes a little endian signed 8 bytes integer. @@ -686,7 +671,7 @@ pub fn le_i64<I, E: ParseError<I>>(input: I) -> IResult<I, i64, E> where I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength, { - map!(input, le_u64, |x| x as i64) + le_u64.map(|x| x as i64).parse(input) } /// Recognizes a little endian signed 16 bytes integer. @@ -705,12 +690,11 @@ where /// assert_eq!(parser(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof)))); /// ``` #[inline] -#[cfg(stable_i128)] pub fn le_i128<I, E: ParseError<I>>(input: I) -> IResult<I, i128, E> where I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength, { - map!(input, le_u128, |x| x as i128) + le_u128.map(|x| x as i128).parse(input) } /// Recognizes an unsigned 1 byte integer @@ -926,7 +910,6 @@ where /// assert_eq!(le_u128(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof)))); /// ``` #[inline] -#[cfg(stable_i128)] pub fn u128<I, E: ParseError<I>>(endian: crate::number::Endianness) -> fn(I) -> IResult<I, u128, E> where I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength, @@ -962,7 +945,7 @@ pub fn i8<I, E: ParseError<I>>(i: I) -> IResult<I, i8, E> where I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength, { - map!(i, u8, |x| x as i8) + u8.map(|x| x as i8).parse(i) } /// Recognizes a signed 2 byte integer @@ -1146,7 +1129,6 @@ where /// assert_eq!(le_i128(&b"\x01"[..]), Err(Err::Error((&[0x01][..], ErrorKind::Eof)))); /// ``` #[inline] -#[cfg(stable_i128)] pub fn i128<I, E: ParseError<I>>(endian: crate::number::Endianness) -> fn(I) -> IResult<I, i128, E> where I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength, @@ -1460,7 +1442,10 @@ where ))(input) } -/// Recognizes a floating point number in text format and returns the integer, fraction and exponent parts of the input data +/// Recognizes a floating point number in text format +/// +/// It returns a tuple of (`sign`, `integer part`, `fraction part` and `exponent`) of the input +/// data. /// /// *Complete version*: Can parse until the end of input. /// @@ -1598,7 +1583,7 @@ where */ let (i, s) = recognize_float_or_exceptions(input)?; match s.parse_to() { - Some(f) => (Ok((i, f))), + Some(f) => Ok((i, f)), None => Err(crate::Err::Error(E::from_error_kind( i, crate::error::ErrorKind::Float, @@ -1651,7 +1636,7 @@ where */ let (i, s) = recognize_float_or_exceptions(input)?; match s.parse_to() { - Some(f) => (Ok((i, f))), + Some(f) => Ok((i, f)), None => Err(crate::Err::Error(E::from_error_kind( i, crate::error::ErrorKind::Float, @@ -1752,7 +1737,6 @@ mod tests { } #[test] - #[cfg(stable_i128)] fn be_i128_tests() { assert_parse!( be_i128( @@ -1869,7 +1853,6 @@ mod tests { } #[test] - #[cfg(stable_i128)] fn le_i128_tests() { assert_parse!( le_i128( @@ -2116,7 +2099,7 @@ mod tests { #[cfg(feature = "std")] fn parse_f64(i: &str) -> IResult<&str, f64, ()> { - match recognize_float(i) { + match recognize_float_or_exceptions(i) { Err(e) => Err(e), Ok((i, s)) => { if s.is_empty() { diff --git a/vendor/nom/src/number/streaming.rs b/vendor/nom/src/number/streaming.rs index 7c53ccc47..b4e856d29 100644 --- a/vendor/nom/src/number/streaming.rs +++ b/vendor/nom/src/number/streaming.rs @@ -12,26 +12,6 @@ use crate::traits::{ AsBytes, AsChar, Compare, InputIter, InputLength, InputTake, InputTakeAtPosition, Offset, Slice, }; -#[doc(hidden)] -macro_rules! map( - // Internal parser, do not use directly - (__impl $i:expr, $submac:ident!( $($args:tt)* ), $g:expr) => ( - $crate::combinator::map(move |i| {$submac!(i, $($args)*)}, $g).parse($i) - ); - ($i:expr, $submac:ident!( $($args:tt)* ), $g:expr) => ( - map!(__impl $i, $submac!($($args)*), $g) - ); - ($i:expr, $f:expr, $g:expr) => ( - map!(__impl $i, call!($f), $g) - ); -); - -#[doc(hidden)] -macro_rules! call ( - ($i:expr, $fun:expr) => ( $fun( $i ) ); - ($i:expr, $fun:expr, $($args:expr),* ) => ( $fun( $i, $($args),* ) ); -); - /// Recognizes an unsigned 1 byte integer. /// /// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there is not enough data. @@ -208,7 +188,6 @@ where /// assert_eq!(parser(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(15)))); /// ``` #[inline] -#[cfg(stable_i128)] pub fn be_u128<I, E: ParseError<I>>(input: I) -> IResult<I, u128, E> where I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength, @@ -243,7 +222,7 @@ pub fn be_i8<I, E: ParseError<I>>(input: I) -> IResult<I, i8, E> where I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength, { - map!(input, be_u8, |x| x as i8) + be_u8.map(|x| x as i8).parse(input) } /// Recognizes a big endian signed 2 bytes integer. @@ -263,7 +242,7 @@ pub fn be_i16<I, E: ParseError<I>>(input: I) -> IResult<I, i16, E> where I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength, { - map!(input, be_u16, |x| x as i16) + be_u16.map(|x| x as i16).parse(input) } /// Recognizes a big endian signed 3 bytes integer. @@ -284,11 +263,15 @@ where I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength, { // Same as the unsigned version but we need to sign-extend manually here - map!(input, be_u24, |x| if x & 0x80_00_00 != 0 { - (x | 0xff_00_00_00) as i32 - } else { - x as i32 - }) + be_u24 + .map(|x| { + if x & 0x80_00_00 != 0 { + (x | 0xff_00_00_00) as i32 + } else { + x as i32 + } + }) + .parse(input) } /// Recognizes a big endian signed 4 bytes integer. @@ -308,7 +291,7 @@ pub fn be_i32<I, E: ParseError<I>>(input: I) -> IResult<I, i32, E> where I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength, { - map!(input, be_u32, |x| x as i32) + be_u32.map(|x| x as i32).parse(input) } /// Recognizes a big endian signed 8 bytes integer. @@ -329,7 +312,7 @@ pub fn be_i64<I, E: ParseError<I>>(input: I) -> IResult<I, i64, E> where I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength, { - map!(input, be_u64, |x| x as i64) + be_u64.map(|x| x as i64).parse(input) } /// Recognizes a big endian signed 16 bytes integer. @@ -345,12 +328,11 @@ where /// assert_eq!(parser(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(15)))); /// ``` #[inline] -#[cfg(stable_i128)] pub fn be_i128<I, E: ParseError<I>>(input: I) -> IResult<I, i128, E> where I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength, { - map!(input, be_u128, |x| x as i128) + be_u128.map(|x| x as i128).parse(input) } /// Recognizes an unsigned 1 byte integer. @@ -528,7 +510,6 @@ where /// assert_eq!(parser(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(15)))); /// ``` #[inline] -#[cfg(stable_i128)] pub fn le_u128<I, E: ParseError<I>>(input: I) -> IResult<I, u128, E> where I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength, @@ -563,7 +544,7 @@ pub fn le_i8<I, E: ParseError<I>>(input: I) -> IResult<I, i8, E> where I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength, { - map!(input, le_u8, |x| x as i8) + le_u8.map(|x| x as i8).parse(input) } /// Recognizes a little endian signed 2 bytes integer. @@ -586,7 +567,7 @@ pub fn le_i16<I, E: ParseError<I>>(input: I) -> IResult<I, i16, E> where I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength, { - map!(input, le_u16, |x| x as i16) + le_u16.map(|x| x as i16).parse(input) } /// Recognizes a little endian signed 3 bytes integer. @@ -610,11 +591,15 @@ where I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength, { // Same as the unsigned version but we need to sign-extend manually here - map!(input, le_u24, |x| if x & 0x80_00_00 != 0 { - (x | 0xff_00_00_00) as i32 - } else { - x as i32 - }) + le_u24 + .map(|x| { + if x & 0x80_00_00 != 0 { + (x | 0xff_00_00_00) as i32 + } else { + x as i32 + } + }) + .parse(input) } /// Recognizes a little endian signed 4 bytes integer. @@ -637,7 +622,7 @@ pub fn le_i32<I, E: ParseError<I>>(input: I) -> IResult<I, i32, E> where I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength, { - map!(input, le_u32, |x| x as i32) + le_u32.map(|x| x as i32).parse(input) } /// Recognizes a little endian signed 8 bytes integer. @@ -660,7 +645,7 @@ pub fn le_i64<I, E: ParseError<I>>(input: I) -> IResult<I, i64, E> where I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength, { - map!(input, le_u64, |x| x as i64) + le_u64.map(|x| x as i64).parse(input) } /// Recognizes a little endian signed 16 bytes integer. @@ -679,12 +664,11 @@ where /// assert_eq!(parser(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(15)))); /// ``` #[inline] -#[cfg(stable_i128)] pub fn le_i128<I, E: ParseError<I>>(input: I) -> IResult<I, i128, E> where I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength, { - map!(input, le_u128, |x| x as i128) + le_u128.map(|x| x as i128).parse(input) } /// Recognizes an unsigned 1 byte integer @@ -900,7 +884,6 @@ where /// assert_eq!(le_u128(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(15)))); /// ``` #[inline] -#[cfg(stable_i128)] pub fn u128<I, E: ParseError<I>>(endian: crate::number::Endianness) -> fn(I) -> IResult<I, u128, E> where I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength, @@ -936,7 +919,7 @@ pub fn i8<I, E: ParseError<I>>(i: I) -> IResult<I, i8, E> where I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength, { - map!(i, u8, |x| x as i8) + u8.map(|x| x as i8).parse(i) } /// Recognizes a signed 2 byte integer @@ -1120,7 +1103,6 @@ where /// assert_eq!(le_i128(&b"\x01"[..]), Err(Err::Incomplete(Needed::new(15)))); /// ``` #[inline] -#[cfg(stable_i128)] pub fn i128<I, E: ParseError<I>>(endian: crate::number::Endianness) -> fn(I) -> IResult<I, i128, E> where I: Slice<RangeFrom<usize>> + InputIter<Item = u8> + InputLength, @@ -1429,7 +1411,10 @@ where ))(input) } -/// Recognizes a floating point number in text format and returns the integer, fraction and exponent parts of the input data +/// Recognizes a floating point number in text format +/// +/// It returns a tuple of (`sign`, `integer part`, `fraction part` and `exponent`) of the input +/// data. /// /// *Streaming version*: Will return `Err(nom::Err::Incomplete(_))` if there is not enough data. /// @@ -1570,7 +1555,7 @@ where */ let (i, s) = recognize_float_or_exceptions(input)?; match s.parse_to() { - Some(f) => (Ok((i, f))), + Some(f) => Ok((i, f)), None => Err(crate::Err::Error(E::from_error_kind( i, crate::error::ErrorKind::Float, @@ -1624,7 +1609,7 @@ where */ let (i, s) = recognize_float_or_exceptions(input)?; match s.parse_to() { - Some(f) => (Ok((i, f))), + Some(f) => Ok((i, f)), None => Err(crate::Err::Error(E::from_error_kind( i, crate::error::ErrorKind::Float, @@ -1768,7 +1753,6 @@ mod tests { } #[test] - #[cfg(stable_i128)] fn i128_tests() { assert_parse!( be_i128( @@ -1948,7 +1932,6 @@ mod tests { } #[test] - #[cfg(stable_i128)] fn le_i128_tests() { assert_parse!( le_i128( @@ -2196,7 +2179,7 @@ mod tests { #[cfg(feature = "std")] fn parse_f64(i: &str) -> IResult<&str, f64, ()> { use crate::traits::ParseTo; - match recognize_float(i) { + match recognize_float_or_exceptions(i) { Err(e) => Err(e), Ok((i, s)) => { if s.is_empty() { |