diff --git a/src/combinator/parser.rs b/src/combinator/impls.rs similarity index 94% rename from src/combinator/parser.rs rename to src/combinator/impls.rs index 1abc0826..c7864594 100644 --- a/src/combinator/parser.rs +++ b/src/combinator/impls.rs @@ -1,3 +1,5 @@ +//! Opaque implementations of [`Parser`] + use crate::combinator::trace; use crate::combinator::trace_result; use crate::combinator::DisplayDebug; @@ -14,7 +16,7 @@ use crate::stream::StreamIsPartial; use crate::stream::{Location, Stream}; use crate::*; -/// Implementation of [`Parser::by_ref`] +/// [`Parser`] implementation for [`Parser::by_ref`] pub struct ByRef<'p, P, I, O, E> { pub(crate) p: &'p mut P, pub(crate) i: core::marker::PhantomData, @@ -32,7 +34,7 @@ where } } -/// Implementation of [`Parser::map`] +/// [`Parser`] implementation for [`Parser::map`] pub struct Map where F: Parser, @@ -60,7 +62,7 @@ where } } -/// Implementation of [`Parser::try_map`] +/// [`Parser`] implementation for [`Parser::try_map`] pub struct TryMap where F: Parser, @@ -97,7 +99,7 @@ where } } -/// Implementation of [`Parser::verify_map`] +/// [`Parser`] implementation for [`Parser::verify_map`] pub struct VerifyMap where F: Parser, @@ -133,7 +135,7 @@ where } } -/// Implementation of [`Parser::and_then`] +/// [`Parser`] implementation for [`Parser::and_then`] pub struct AndThen where F: Parser, @@ -169,7 +171,7 @@ where } } -/// Implementation of [`Parser::parse_to`] +/// [`Parser`] implementation for [`Parser::parse_to`] pub struct ParseTo where P: Parser, @@ -204,7 +206,7 @@ where } } -/// Implementation of [`Parser::flat_map`] +/// [`Parser`] implementation for [`Parser::flat_map`] pub struct FlatMap where F: Parser, @@ -233,7 +235,7 @@ where } } -/// Implementation of [`Parser::complete_err`] +/// [`Parser`] implementation for [`Parser::complete_err`] pub struct CompleteErr { pub(crate) p: P, pub(crate) i: core::marker::PhantomData, @@ -261,7 +263,7 @@ where } } -/// Implementation of [`Parser::verify`] +/// [`Parser`] implementation for [`Parser::verify`] pub struct Verify where F: Parser, @@ -301,7 +303,7 @@ where } } -/// Implementation of [`Parser::value`] +/// [`Parser`] implementation for [`Parser::value`] pub struct Value where F: Parser, @@ -325,7 +327,7 @@ where } } -/// Implementation of [`Parser::default_value`] +/// [`Parser`] implementation for [`Parser::default_value`] pub struct DefaultValue where F: Parser, @@ -349,7 +351,7 @@ where } } -/// Implementation of [`Parser::void`] +/// [`Parser`] implementation for [`Parser::void`] pub struct Void where F: Parser, @@ -374,7 +376,7 @@ where #[deprecated(since = "0.6.14", note = "Replaced with `Take`")] pub type Recognize = Take; -/// Implementation of [`Parser::take`] +/// [`Parser`] implementation for [`Parser::take`] pub struct Take where F: Parser, @@ -410,7 +412,7 @@ where #[deprecated(since = "0.6.14", note = "Replaced with `WithTaken`")] pub type WithRecognized = WithTaken; -/// Implementation of [`Parser::with_taken`] +/// [`Parser`] implementation for [`Parser::with_taken`] pub struct WithTaken where F: Parser, @@ -442,7 +444,7 @@ where } } -/// Implementation of [`Parser::span`] +/// [`Parser`] implementation for [`Parser::span`] pub struct Span where F: Parser, @@ -469,7 +471,7 @@ where } } -/// Implementation of [`Parser::with_span`] +/// [`Parser`] implementation for [`Parser::with_span`] pub struct WithSpan where F: Parser, @@ -496,7 +498,7 @@ where } } -/// Implementation of [`Parser::output_into`] +/// [`Parser`] implementation for [`Parser::output_into`] pub struct OutputInto where F: Parser, @@ -520,7 +522,7 @@ where } } -/// Implementation of [`Parser::err_into`] +/// [`Parser`] implementation for [`Parser::err_into`] pub struct ErrInto where F: Parser, @@ -549,7 +551,7 @@ where } } -/// Implementation of [`Parser::context`] +/// [`Parser`] implementation for [`Parser::context`] pub struct Context where F: Parser, @@ -584,7 +586,7 @@ where } } -/// Implementation of [`Parser::retry_after`] +/// [`Parser`] implementation for [`Parser::retry_after`] #[cfg(feature = "unstable-recover")] #[cfg(feature = "std")] pub struct RetryAfter @@ -660,7 +662,7 @@ where } } -/// Implementation of [`Parser::resume_after`] +/// [`Parser`] implementation for [`Parser::resume_after`] #[cfg(feature = "unstable-recover")] #[cfg(feature = "std")] pub struct ResumeAfter diff --git a/src/combinator/mod.rs b/src/combinator/mod.rs index df791ada..a7f540c5 100644 --- a/src/combinator/mod.rs +++ b/src/combinator/mod.rs @@ -163,17 +163,19 @@ mod branch; mod core; mod debug; mod multi; -mod parser; mod sequence; #[cfg(test)] mod tests; +pub mod impls; + pub use self::branch::*; pub use self::core::*; pub use self::debug::*; +#[deprecated(since = "0.6.23", note = "Replaced with `combinator::impls`")] +pub use self::impls::*; pub use self::multi::*; -pub use self::parser::*; pub use self::sequence::*; #[allow(unused_imports)] diff --git a/src/combinator/multi.rs b/src/combinator/multi.rs index dfff88e3..9d5f9fdc 100644 --- a/src/combinator/multi.rs +++ b/src/combinator/multi.rs @@ -132,7 +132,7 @@ where } } -/// Implementation of [`repeat`] +/// Customizable [`Parser`] implementation for [`repeat`] pub struct Repeat where P: Parser, diff --git a/src/parser.rs b/src/parser.rs index 74101af9..2fe2d289 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -1,7 +1,7 @@ //! Basic types to build the parsers use crate::ascii::Caseless as AsciiCaseless; -use crate::combinator::*; +use crate::combinator::impls; #[cfg(feature = "unstable-recover")] #[cfg(feature = "std")] use crate::error::FromRecoverableError; @@ -91,7 +91,7 @@ pub trait Parser { /// - Migrating from older versions / `nom` /// - Testing [`Parser`]s /// - /// For look-ahead parsing, see instead [`peek`]. + /// For look-ahead parsing, see instead [`peek`][crate::combinator::peek]. /// /// #[inline(always)] @@ -146,11 +146,11 @@ pub trait Parser { /// } /// ``` #[inline(always)] - fn by_ref(&mut self) -> ByRef<'_, Self, I, O, E> + fn by_ref(&mut self) -> impls::ByRef<'_, Self, I, O, E> where Self: core::marker::Sized, { - ByRef { + impls::ByRef { p: self, i: Default::default(), o: Default::default(), @@ -175,12 +175,12 @@ pub trait Parser { /// ``` #[doc(alias = "to")] #[inline(always)] - fn value(self, val: O2) -> Value + fn value(self, val: O2) -> impls::Value where Self: core::marker::Sized, O2: Clone, { - Value { + impls::Value { parser: self, val, i: Default::default(), @@ -205,12 +205,12 @@ pub trait Parser { /// # } /// ``` #[inline(always)] - fn default_value(self) -> DefaultValue + fn default_value(self) -> impls::DefaultValue where Self: core::marker::Sized, O2: core::default::Default, { - DefaultValue { + impls::DefaultValue { parser: self, o2: Default::default(), i: Default::default(), @@ -235,11 +235,11 @@ pub trait Parser { /// # } /// ``` #[inline(always)] - fn void(self) -> Void + fn void(self) -> impls::Void where Self: core::marker::Sized, { - Void { + impls::Void { parser: self, i: Default::default(), o: Default::default(), @@ -269,12 +269,12 @@ pub trait Parser { /// # } /// ``` #[inline(always)] - fn output_into(self) -> OutputInto + fn output_into(self) -> impls::OutputInto where Self: core::marker::Sized, O: Into, { - OutputInto { + impls::OutputInto { parser: self, i: Default::default(), o: Default::default(), @@ -302,12 +302,12 @@ pub trait Parser { #[doc(alias = "concat")] #[doc(alias = "recognize")] #[inline(always)] - fn take(self) -> Take + fn take(self) -> impls::Take where Self: core::marker::Sized, I: Stream, { - Take { + impls::Take { parser: self, i: Default::default(), o: Default::default(), @@ -318,12 +318,12 @@ pub trait Parser { /// Replaced with [`Parser::take`] #[inline(always)] #[deprecated(since = "0.6.14", note = "Replaced with `Parser::take`")] - fn recognize(self) -> Take + fn recognize(self) -> impls::Take where Self: core::marker::Sized, I: Stream, { - Take { + impls::Take { parser: self, i: Default::default(), o: Default::default(), @@ -370,12 +370,12 @@ pub trait Parser { #[doc(alias = "consumed")] #[doc(alias = "with_recognized")] #[inline(always)] - fn with_taken(self) -> WithTaken + fn with_taken(self) -> impls::WithTaken where Self: core::marker::Sized, I: Stream, { - WithTaken { + impls::WithTaken { parser: self, i: Default::default(), o: Default::default(), @@ -386,12 +386,12 @@ pub trait Parser { /// Replaced with [`Parser::with_taken`] #[inline(always)] #[deprecated(since = "0.6.14", note = "Replaced with `Parser::with_taken`")] - fn with_recognized(self) -> WithTaken + fn with_recognized(self) -> impls::WithTaken where Self: core::marker::Sized, I: Stream, { - WithTaken { + impls::WithTaken { parser: self, i: Default::default(), o: Default::default(), @@ -416,12 +416,12 @@ pub trait Parser { /// assert_eq!(parser.parse_peek(LocatingSlice::new("abcd;")),Err(ErrMode::Backtrack(InputError::new(LocatingSlice::new("abcd;").peek_slice(4).0, ErrorKind::Literal)))); /// ``` #[inline(always)] - fn span(self) -> Span + fn span(self) -> impls::Span where Self: core::marker::Sized, I: Stream + Location, { - Span { + impls::Span { parser: self, i: Default::default(), o: Default::default(), @@ -470,12 +470,12 @@ pub trait Parser { /// # } /// ``` #[inline(always)] - fn with_span(self) -> WithSpan + fn with_span(self) -> impls::WithSpan where Self: core::marker::Sized, I: Stream + Location, { - WithSpan { + impls::WithSpan { parser: self, i: Default::default(), o: Default::default(), @@ -502,12 +502,12 @@ pub trait Parser { /// # } /// ``` #[inline(always)] - fn map(self, map: G) -> Map + fn map(self, map: G) -> impls::Map where G: FnMut(O) -> O2, Self: core::marker::Sized, { - Map { + impls::Map { parser: self, map, i: Default::default(), @@ -539,14 +539,14 @@ pub trait Parser { /// # } /// ``` #[inline(always)] - fn try_map(self, map: G) -> TryMap + fn try_map(self, map: G) -> impls::TryMap where Self: core::marker::Sized, G: FnMut(O) -> Result, I: Stream, E: FromExternalError, { - TryMap { + impls::TryMap { parser: self, map, i: Default::default(), @@ -582,14 +582,14 @@ pub trait Parser { #[doc(alias = "filter_map")] #[doc(alias = "map_opt")] #[inline(always)] - fn verify_map(self, map: G) -> VerifyMap + fn verify_map(self, map: G) -> impls::VerifyMap where Self: core::marker::Sized, G: FnMut(O) -> Option, I: Stream, E: ParserError, { - VerifyMap { + impls::VerifyMap { parser: self, map, i: Default::default(), @@ -632,13 +632,13 @@ pub trait Parser { /// assert_eq!(length_take.parse_peek(&[4, 0, 1, 2][..]), Err(ErrMode::Backtrack(InputError::new(&[0, 1, 2][..], ErrorKind::Slice)))); /// ``` #[inline(always)] - fn flat_map(self, map: G) -> FlatMap + fn flat_map(self, map: G) -> impls::FlatMap where Self: core::marker::Sized, G: FnMut(O) -> H, H: Parser, { - FlatMap { + impls::FlatMap { f: self, g: map, h: Default::default(), @@ -667,14 +667,14 @@ pub trait Parser { /// # } /// ``` #[inline(always)] - fn and_then(self, inner: G) -> AndThen + fn and_then(self, inner: G) -> impls::AndThen where Self: core::marker::Sized, G: Parser, O: StreamIsPartial, I: Stream, { - AndThen { + impls::AndThen { outer: self, inner, i: Default::default(), @@ -705,14 +705,14 @@ pub trait Parser { /// ``` #[doc(alias = "from_str")] #[inline(always)] - fn parse_to(self) -> ParseTo + fn parse_to(self) -> impls::ParseTo where Self: core::marker::Sized, I: Stream, O: ParseSlice, E: ParserError, { - ParseTo { + impls::ParseTo { p: self, i: Default::default(), o: Default::default(), @@ -743,7 +743,7 @@ pub trait Parser { #[doc(alias = "satisfy")] #[doc(alias = "filter")] #[inline(always)] - fn verify(self, filter: G) -> Verify + fn verify(self, filter: G) -> impls::Verify where Self: core::marker::Sized, G: FnMut(&O2) -> bool, @@ -752,7 +752,7 @@ pub trait Parser { O2: ?Sized, E: ParserError, { - Verify { + impls::Verify { parser: self, filter, i: Default::default(), @@ -768,14 +768,14 @@ pub trait Parser { /// to errors when backtracking through a parse tree. #[doc(alias = "labelled")] #[inline(always)] - fn context(self, context: C) -> Context + fn context(self, context: C) -> impls::Context where Self: core::marker::Sized, I: Stream, E: AddContext, C: Clone + crate::lib::std::fmt::Debug, { - Context { + impls::Context { parser: self, context, i: Default::default(), @@ -800,11 +800,11 @@ pub trait Parser { /// # } /// ``` #[inline(always)] - fn complete_err(self) -> CompleteErr + fn complete_err(self) -> impls::CompleteErr where Self: core::marker::Sized, { - CompleteErr { + impls::CompleteErr { p: self, i: Default::default(), o: Default::default(), @@ -814,12 +814,12 @@ pub trait Parser { /// Convert the parser's error to another type using [`std::convert::From`] #[inline(always)] - fn err_into(self) -> ErrInto + fn err_into(self) -> impls::ErrInto where Self: core::marker::Sized, E: Into, { - ErrInto { + impls::ErrInto { parser: self, i: Default::default(), o: Default::default(), @@ -838,7 +838,7 @@ pub trait Parser { #[inline(always)] #[cfg(feature = "unstable-recover")] #[cfg(feature = "std")] - fn retry_after(self, recover: R) -> RetryAfter + fn retry_after(self, recover: R) -> impls::RetryAfter where Self: core::marker::Sized, R: Parser, @@ -846,7 +846,7 @@ pub trait Parser { I: Recover, E: FromRecoverableError, { - RetryAfter { + impls::RetryAfter { parser: self, recover, i: Default::default(), @@ -862,7 +862,7 @@ pub trait Parser { #[inline(always)] #[cfg(feature = "unstable-recover")] #[cfg(feature = "std")] - fn resume_after(self, recover: R) -> ResumeAfter + fn resume_after(self, recover: R) -> impls::ResumeAfter where Self: core::marker::Sized, R: Parser, @@ -870,7 +870,7 @@ pub trait Parser { I: Recover, E: FromRecoverableError, { - ResumeAfter { + impls::ResumeAfter { parser: self, recover, i: Default::default(),