diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3ac8db900..31d0dc5f9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -190,9 +190,10 @@ jobs: uses: actions-rs/cargo@v1 with: command: tarpaulin - args: --output-dir coverage --out Lcov + args: --output-dir coverage --out xml --workspace --exclude benchmarks - - name: Publish to Coveralls - uses: coverallsapp/github-action@master + - name: Upload coverage reports to Codecov + uses: codecov/codecov-action@v4.0.1 with: - github-token: ${{ secrets.GITHUB_TOKEN }} + token: ${{ secrets.CODECOV_TOKEN }} + slug: rust-bakery/nom diff --git a/Cargo.toml b/Cargo.toml index cb2c145a1..7820e9c0c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "nom" -version = "7.1.2" +version = "8.0.0-alpha1" authors = ["contact@geoffroycouprie.com"] description = "A byte-oriented, zero-copy, parser combinators library" license = "MIT" diff --git a/src/bytes/complete.rs b/src/bytes/complete.rs index a53b2dd64..1d43c7502 100644 --- a/src/bytes/complete.rs +++ b/src/bytes/complete.rs @@ -4,7 +4,7 @@ use core::marker::PhantomData; use crate::error::ParseError; use crate::internal::{IResult, Parser}; -use crate::traits::{Compare, FindSubstring, FindToken, InputLength, ToUsize}; +use crate::traits::{Compare, FindSubstring, FindToken, ToUsize}; use crate::Complete; use crate::Emit; use crate::Input; @@ -32,7 +32,7 @@ use crate::OutputM; pub fn tag>(tag: T) -> impl Fn(I) -> IResult where I: Input + Compare, - T: InputLength + Clone, + T: Input + Clone, { move |i: I| { let mut parser = super::Tag { @@ -68,7 +68,7 @@ where pub fn tag_no_case>(tag: T) -> impl Fn(I) -> IResult where I: Input + Compare, - T: InputLength + Clone, + T: Input + Clone, { move |i: I| { let mut parser = super::TagNoCase { @@ -359,7 +359,7 @@ where pub fn take_until>(tag: T) -> impl FnMut(I) -> IResult where I: Input + FindSubstring, - T: InputLength + Clone, + T: Input + Clone, { let mut parser = super::take_until(tag); @@ -388,7 +388,7 @@ where pub fn take_until1>(tag: T) -> impl FnMut(I) -> IResult where I: Input + FindSubstring, - T: InputLength + Clone, + T: Input + Clone, { let mut parser = super::take_until1(tag); diff --git a/src/bytes/mod.rs b/src/bytes/mod.rs index cf901b9f8..b720df394 100644 --- a/src/bytes/mod.rs +++ b/src/bytes/mod.rs @@ -11,7 +11,7 @@ use crate::error::ErrorKind; use crate::error::ParseError; use crate::internal::{Err, Needed, Parser}; use crate::lib::std::result::Result::*; -use crate::traits::{Compare, CompareResult, InputLength}; +use crate::traits::{Compare, CompareResult}; use crate::AsChar; use crate::Check; use crate::ExtendInto; @@ -45,7 +45,7 @@ use crate::ToUsize; pub fn tag>(tag: T) -> impl Parser where I: Input + Compare, - T: InputLength + Clone, + T: Input + Clone, { Tag { tag, @@ -62,7 +62,7 @@ pub struct Tag { impl, T> Parser for Tag where I: Input + Compare, - T: InputLength + Clone, + T: Input + Clone, { type Output = I; @@ -114,7 +114,7 @@ where pub fn tag_no_case>(tag: T) -> impl Parser where I: Input + Compare, - T: InputLength + Clone, + T: Input + Clone, { TagNoCase { tag, @@ -131,7 +131,7 @@ pub struct TagNoCase { impl, T> Parser for TagNoCase where I: Input + Compare, - T: InputLength + Clone, + T: Input + Clone, { type Output = I; diff --git a/src/bytes/streaming.rs b/src/bytes/streaming.rs index c32e97b85..081643669 100644 --- a/src/bytes/streaming.rs +++ b/src/bytes/streaming.rs @@ -4,7 +4,7 @@ use core::marker::PhantomData; use crate::error::ParseError; use crate::internal::{IResult, Parser}; -use crate::traits::{Compare, FindSubstring, FindToken, InputLength, ToUsize}; +use crate::traits::{Compare, FindSubstring, FindToken, ToUsize}; use crate::Emit; use crate::Input; use crate::OutputM; @@ -31,7 +31,7 @@ use crate::Streaming; pub fn tag>(tag: T) -> impl Fn(I) -> IResult where I: Input + Compare, - T: InputLength + Clone, + T: Input + Clone, { move |i: I| { let mut parser = super::Tag { @@ -65,7 +65,7 @@ where pub fn tag_no_case>(tag: T) -> impl Fn(I) -> IResult where I: Input + Compare, - T: InputLength + Clone, + T: Input + Clone, { move |i: I| { let mut parser = super::TagNoCase { @@ -338,7 +338,7 @@ where /// ``` pub fn take>(count: C) -> impl FnMut(I) -> IResult where - I: Input + InputLength, + I: Input, C: ToUsize, { let mut parser = super::take(count); diff --git a/src/bytes/tests.rs b/src/bytes/tests.rs index 15106bf32..3e76537ff 100644 --- a/src/bytes/tests.rs +++ b/src/bytes/tests.rs @@ -636,10 +636,10 @@ fn tag_fixed_size_array() { use crate::bytes::streaming::tag; fn test(i: &[u8]) -> IResult<&[u8], &[u8]> { - tag([0x42])(i) + tag(&[0x42][..])(i) } fn test2(i: &[u8]) -> IResult<&[u8], &[u8]> { - tag(&[0x42])(i) + tag(&[0x42][..])(i) } let input = [0x42, 0x00]; assert_eq!(test(&input), Ok((&b"\x00"[..], &b"\x42"[..]))); diff --git a/src/character/complete.rs b/src/character/complete.rs index 17b5eb29f..6dc334995 100644 --- a/src/character/complete.rs +++ b/src/character/complete.rs @@ -7,7 +7,7 @@ use crate::combinator::opt; use crate::error::ErrorKind; use crate::error::ParseError; use crate::internal::{Err, IResult}; -use crate::traits::{AsChar, FindToken, Input, InputLength}; +use crate::traits::{AsChar, FindToken, Input}; use crate::traits::{Compare, CompareResult}; use crate::Complete; use crate::Emit; @@ -208,7 +208,7 @@ where /// ``` pub fn line_ending>(input: T) -> IResult where - T: Input + InputLength, + T: Input, T: Compare<&'static str>, { match input.compare("\n") { diff --git a/src/combinator/mod.rs b/src/combinator/mod.rs index bfd4a994a..96faa3faa 100644 --- a/src/combinator/mod.rs +++ b/src/combinator/mod.rs @@ -15,7 +15,7 @@ use crate::lib::std::convert::Into; use crate::lib::std::fmt::Debug; use crate::lib::std::mem::transmute; use crate::lib::std::ops::{Range, RangeFrom, RangeTo}; -use crate::traits::{AsChar, Input, InputLength, ParseTo}; +use crate::traits::{AsChar, Input, ParseTo}; use crate::traits::{Compare, CompareResult, Offset}; #[cfg(test)] @@ -48,7 +48,7 @@ where #[inline] pub fn rest_len>(input: T) -> IResult where - T: InputLength, + T: Input, { let len = input.input_len(); Ok((input, len)) @@ -363,7 +363,7 @@ where /// assert_eq!(parser(""), Ok(("", ""))); /// # } /// ``` -pub fn eof>(input: I) -> IResult { +pub fn eof>(input: I) -> IResult { if input.input_len() == 0 { let clone = input.clone(); Ok((input, clone)) @@ -443,7 +443,7 @@ pub fn all_consuming, F>( parser: F, ) -> impl Parser>::Output, Error = E> where - I: InputLength, + I: Input, F: Parser, { AllConsuming { parser } @@ -456,7 +456,7 @@ pub struct AllConsuming { impl Parser for AllConsuming where - I: InputLength, + I: Input, F: Parser, { type Output = >::Output; diff --git a/src/internal.rs b/src/internal.rs index e5896799d..956498fff 100644 --- a/src/internal.rs +++ b/src/internal.rs @@ -47,7 +47,6 @@ impl Finish for IResult { /// Contains information on needed data if a parser returned `Incomplete` #[derive(Debug, PartialEq, Eq, Clone, Copy)] -#[cfg_attr(nightly, warn(rustdoc::missing_doc_code_examples))] pub enum Needed { /// Needs more data, but we do not know how much Unknown, @@ -99,7 +98,6 @@ impl Needed { /// See also: [`Finish`]. /// #[derive(Debug, Clone, PartialEq)] -#[cfg_attr(nightly, warn(rustdoc::missing_doc_code_examples))] pub enum Err { /// There was not enough data Incomplete(Needed), @@ -579,7 +577,6 @@ impl> Parser for Box { f: F, g: G, @@ -660,7 +657,6 @@ where } /// Implementation of `Parser::flat_map` -#[cfg_attr(nightly, warn(rustdoc::missing_doc_code_examples))] pub struct FlatMap { f: F, g: G, @@ -687,7 +683,6 @@ impl< } /// Implementation of `Parser::and_then` -#[cfg_attr(nightly, warn(rustdoc::missing_doc_code_examples))] pub struct AndThen { f: F, g: G, @@ -710,7 +705,6 @@ impl, G: Parser<>::Output, Error = { f: F, g: G, @@ -732,7 +726,6 @@ impl, F: Parser, G: Parser> Pars } /// Implementation of `Parser::or` -#[cfg_attr(nightly, warn(rustdoc::missing_doc_code_examples))] pub struct Or { f: F, g: G, @@ -761,7 +754,6 @@ impl< } /// Implementation of `Parser::into` -#[cfg_attr(nightly, warn(rustdoc::missing_doc_code_examples))] pub struct Into { f: F, phantom_out2: core::marker::PhantomData, diff --git a/src/lib.rs b/src/lib.rs index d6b5b15d1..409910e30 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -379,7 +379,6 @@ #![cfg_attr(feature = "docsrs", feature(doc_cfg))] #![allow(clippy::doc_markdown)] #![deny(missing_docs)] -#[cfg_attr(nightly, warn(rustdoc::missing_doc_code_examples))] #[cfg(feature = "alloc")] #[macro_use] extern crate alloc; @@ -391,12 +390,10 @@ doc_comment::doctest!("../README.md"); /// Lib module to re-export everything needed from `std` or `core`/`alloc`. This is how `serde` does /// it, albeit there it is not public. -#[cfg_attr(nightly, allow(rustdoc::missing_doc_code_examples))] pub mod lib { /// `std` facade allowing `std`/`core` to be interchangeable. Reexports `alloc` crate optionally, /// as well as `core` or `std` #[cfg(not(feature = "std"))] - #[cfg_attr(nightly, allow(rustdoc::missing_doc_code_examples))] /// internal std exports for no_std compatibility pub mod std { #[doc(hidden)] @@ -418,7 +415,6 @@ pub mod lib { } #[cfg(feature = "std")] - #[cfg_attr(nightly, allow(rustdoc::missing_doc_code_examples))] /// internal std exports for no_std compatibility pub mod std { #[doc(hidden)] diff --git a/src/multi/mod.rs b/src/multi/mod.rs index ba67bc180..45168f5b2 100644 --- a/src/multi/mod.rs +++ b/src/multi/mod.rs @@ -12,16 +12,14 @@ use crate::internal::{Err, Needed, Parser}; use crate::lib::std::num::NonZeroUsize; #[cfg(feature = "alloc")] use crate::lib::std::vec::Vec; +use crate::traits::ToUsize; use crate::Check; use crate::Emit; use crate::Input; use crate::Mode; +use crate::NomRange; use crate::OutputM; use crate::OutputMode; -use crate::{ - traits::{InputLength, ToUsize}, - NomRange, -}; /// Don't pre-allocate more than 64KiB when calling `Vec::with_capacity`. /// @@ -66,7 +64,7 @@ pub fn many0( f: F, ) -> impl Parser>::Output>, Error = >::Error> where - I: Clone + InputLength, + I: Clone + Input, F: Parser, { Many0 { parser: f } @@ -81,7 +79,7 @@ pub struct Many0 { #[cfg(feature = "alloc")] impl Parser for Many0 where - I: Clone + InputLength, + I: Clone + Input, F: Parser, { type Output = crate::lib::std::vec::Vec<>::Output>; @@ -153,7 +151,7 @@ pub fn many1( parser: F, ) -> impl Parser>::Output>, Error = >::Error> where - I: Clone + InputLength, + I: Clone + Input, F: Parser, { Many1 { parser } @@ -168,7 +166,7 @@ pub struct Many1 { #[cfg(feature = "alloc")] impl Parser for Many1 where - I: Clone + InputLength, + I: Clone + Input, F: Parser, { type Output = Vec<>::Output>; @@ -255,7 +253,7 @@ pub fn many_till( g: G, ) -> impl Parser>::Output>, >::Output), Error = E> where - I: Clone + InputLength, + I: Clone + Input, F: Parser, G: Parser, E: ParseError, @@ -278,7 +276,7 @@ pub struct ManyTill { #[cfg(feature = "alloc")] impl Parser for ManyTill where - I: Clone + InputLength, + I: Clone + Input, F: Parser, G: Parser, E: ParseError, @@ -337,7 +335,7 @@ where /// [`cut`][crate::combinator::cut]. /// /// # Arguments -/// * `sep` Parses the separator between list elements. Must be consuming. +/// * `sep` Parses the separator between list elements. Must be consuming. /// * `f` Parses the elements of the list. /// /// ```rust @@ -362,7 +360,7 @@ pub fn separated_list0( f: F, ) -> impl Parser>::Output>, Error = E> where - I: Clone + InputLength, + I: Clone + Input, F: Parser, G: Parser, E: ParseError, @@ -383,7 +381,7 @@ pub struct SeparatedList0 { #[cfg(feature = "alloc")] impl, F, G> Parser for SeparatedList0 where - I: Clone + InputLength, + I: Clone + Input, F: Parser, G: Parser, { @@ -482,7 +480,7 @@ pub fn separated_list1( parser: F, ) -> impl Parser>::Output>, Error = E> where - I: Clone + InputLength, + I: Clone + Input, F: Parser, G: Parser, E: ParseError, @@ -500,7 +498,7 @@ pub struct SeparatedList1 { #[cfg(feature = "alloc")] impl, F, G> Parser for SeparatedList1 where - I: Clone + InputLength, + I: Clone + Input, F: Parser, G: Parser, { @@ -599,7 +597,7 @@ pub fn many_m_n( parser: F, ) -> impl Parser>::Output>, Error = E> where - I: Clone + InputLength, + I: Clone + Input, F: Parser, E: ParseError, { @@ -617,7 +615,7 @@ pub struct ManyMN { #[cfg(feature = "alloc")] impl Parser for ManyMN where - I: Clone + InputLength, + I: Clone + Input, F: Parser, { type Output = Vec<>::Output>; @@ -702,7 +700,7 @@ where /// ``` pub fn many0_count(parser: F) -> impl Parser where - I: Clone + InputLength, + I: Clone + Input, F: Parser, E: ParseError, { @@ -716,7 +714,7 @@ pub struct Many0Count { impl Parser for Many0Count where - I: Clone + InputLength, + I: Clone + Input, F: Parser, { type Output = usize; @@ -783,7 +781,7 @@ where /// ``` pub fn many1_count(parser: F) -> impl Parser where - I: Clone + InputLength, + I: Clone + Input, F: Parser, E: ParseError, { @@ -797,7 +795,7 @@ pub struct Many1Count { impl Parser for Many1Count where - I: Clone + InputLength, + I: Clone + Input, F: Parser, { type Output = usize; @@ -1048,7 +1046,7 @@ pub fn fold_many0( g: G, ) -> impl Parser where - I: Clone + InputLength, + I: Clone + Input, F: Parser, G: FnMut(R, >::Output) -> R, H: FnMut() -> R, @@ -1072,7 +1070,7 @@ pub struct FoldMany0 { impl Parser for FoldMany0 where - I: Clone + InputLength, + I: Clone + Input, F: Parser, G: FnMut(R, >::Output) -> R, Init: FnMut() -> R, @@ -1152,7 +1150,7 @@ pub fn fold_many1( g: G, ) -> impl Parser where - I: Clone + InputLength, + I: Clone + Input, F: Parser, G: FnMut(R, >::Output) -> R, H: FnMut() -> R, @@ -1176,7 +1174,7 @@ pub struct FoldMany1 { impl Parser for FoldMany1 where - I: Clone + InputLength, + I: Clone + Input, F: Parser, G: FnMut(R, >::Output) -> R, Init: FnMut() -> R, @@ -1274,7 +1272,7 @@ pub fn fold_many_m_n( g: G, ) -> impl Parser where - I: Clone + InputLength, + I: Clone + Input, F: Parser, G: FnMut(R, >::Output) -> R, H: FnMut() -> R, @@ -1302,7 +1300,7 @@ pub struct FoldManyMN { impl Parser for FoldManyMN where - I: Clone + InputLength, + I: Clone + Input, F: Parser, G: FnMut(R, >::Output) -> R, Init: FnMut() -> R, @@ -1668,7 +1666,7 @@ pub fn many( parser: F, ) -> impl Parser where - I: Clone + InputLength, + I: Clone + Input, F: Parser, Collection: Extend<>::Output> + Default, E: ParseError, @@ -1690,7 +1688,7 @@ pub struct Many { impl Parser for Many where - I: Clone + InputLength, + I: Clone + Input, F: Parser, Collection: Extend<>::Output> + Default, R: NomRange, @@ -1792,7 +1790,7 @@ pub fn fold( fold: G, ) -> impl Parser where - I: Clone + InputLength, + I: Clone + Input, F: Parser, G: FnMut(R, >::Output) -> R, H: FnMut() -> R, @@ -1817,7 +1815,7 @@ pub struct Fold { impl Parser for Fold where - I: Clone + InputLength, + I: Clone + Input, F: Parser, G: FnMut(Res, >::Output) -> Res, H: FnMut() -> Res, diff --git a/src/sequence/mod.rs b/src/sequence/mod.rs index 015db3f76..369796964 100644 --- a/src/sequence/mod.rs +++ b/src/sequence/mod.rs @@ -272,17 +272,17 @@ macro_rules! tuple_trait_impl( macro_rules! tuple_trait_inner( ($it:tt, $self:expr, $input:expr, (), $head:ident $($id:ident)+) => ({ - let (i, o) = $self.$it.parse($input.clone())?; + let (i, o) = $self.$it.parse($input)?; succ!($it, tuple_trait_inner!($self, i, ( o ), $($id)+)) }); ($it:tt, $self:expr, $input:expr, ($($parsed:tt)*), $head:ident $($id:ident)+) => ({ - let (i, o) = $self.$it.parse($input.clone())?; + let (i, o) = $self.$it.parse($input)?; succ!($it, tuple_trait_inner!($self, i, ($($parsed)* , o), $($id)+)) }); ($it:tt, $self:expr, $input:expr, ($($parsed:tt)*), $head:ident) => ({ - let (i, o) = $self.$it.parse($input.clone())?; + let (i, o) = $self.$it.parse($input)?; Ok((i, ($($parsed)* , o))) }); diff --git a/src/traits.rs b/src/traits.rs index b1980ff06..2325ca34d 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -553,36 +553,6 @@ impl<'a> Input for &'a str { } } -/// Abstract method to calculate the input length -pub trait InputLength { - /// Calculates the input length, as indicated by its name, - /// and the name of the trait itself - fn input_len(&self) -> usize; -} - -impl<'a, T> InputLength for &'a [T] { - #[inline] - fn input_len(&self) -> usize { - self.len() - } -} - -impl<'a> InputLength for &'a str { - #[inline] - fn input_len(&self) -> usize { - self.len() - } -} - -impl<'a> InputLength for (&'a [u8], usize) { - #[inline] - fn input_len(&self) -> usize { - //println!("bit input length for ({:?}, {}):", self.0, self.1); - //println!("-> {}", self.0.len() * 8 - self.1); - self.0.len() * 8 - self.1 - } -} - /// Useful functions to calculate the offset between slices and show a hexdump of a slice pub trait Offset { /// Offset between the first byte of self and the first byte of the argument @@ -1080,20 +1050,6 @@ impl<'a, R: FromStr> ParseTo for &'a str { } } -impl InputLength for [u8; N] { - #[inline] - fn input_len(&self) -> usize { - self.len() - } -} - -impl<'a, const N: usize> InputLength for &'a [u8; N] { - #[inline] - fn input_len(&self) -> usize { - self.len() - } -} - impl<'a, const N: usize> Compare<[u8; N]> for &'a [u8] { #[inline(always)] fn compare(&self, t: [u8; N]) -> CompareResult { diff --git a/tests/issues.rs b/tests/issues.rs index fad916c47..ecff7b3a2 100644 --- a/tests/issues.rs +++ b/tests/issues.rs @@ -105,7 +105,7 @@ fn issue_717(i: &[u8]) -> IResult<&[u8], Vec<&[u8]>> { use nom::bytes::complete::{is_not, tag}; use nom::multi::separated_list0; - separated_list0(tag([0x0]), is_not([0x0u8])).parse(i) + separated_list0(tag(&[0x0][..]), is_not([0x0u8])).parse(i) } mod issue_647 {