aboutsummaryrefslogtreecommitdiff
path: root/src/combinator/core.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/combinator/core.rs')
-rw-r--r--src/combinator/core.rs28
1 files changed, 19 insertions, 9 deletions
diff --git a/src/combinator/core.rs b/src/combinator/core.rs
index d784b4e..efd7758 100644
--- a/src/combinator/core.rs
+++ b/src/combinator/core.rs
@@ -1,6 +1,6 @@
+use crate::combinator::trace;
use crate::error::{ErrMode, ErrorKind, Needed, ParserError};
use crate::stream::Stream;
-use crate::trace::trace;
use crate::*;
/// Return the remaining input.
@@ -225,6 +225,8 @@ where
/// This commits the parse result, preventing alternative branch paths like with
/// [`winnow::combinator::alt`][crate::combinator::alt].
///
+/// See the [tutorial][crate::_tutorial::chapter_6] for more details.
+///
/// # Example
///
/// Without `cut_err`:
@@ -331,7 +333,7 @@ where
/// Call the iterator's [`ParserIterator::finish`] method to get the remaining input if successful,
/// or the error value if we encountered an error.
///
-/// On [`ErrMode::Backtrack`], iteration will stop. To instead chain an error up, see [`cut_err`].
+/// On [`ErrMode::Backtrack`], iteration will stop. To instead chain an error up, see [`cut_err`].
///
/// # Example
///
@@ -432,11 +434,16 @@ enum State<E> {
Incomplete(Needed),
}
-/// Always succeeds with given value without consuming any input.
+/// Succeed, consuming no input
///
/// For example, it can be used as the last alternative in `alt` to
/// specify the default case.
///
+/// Useful with:
+/// - [`Parser::value`]
+/// - [`Parser::default_value`]
+/// - [`Parser::map`]
+///
/// **Note:** This never advances the [`Stream`]
///
/// # Example
@@ -445,16 +452,13 @@ enum State<E> {
/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError};
/// # use winnow::prelude::*;
/// use winnow::combinator::alt;
-/// use winnow::combinator::success;
-///
-/// let mut parser = success::<_,_,InputError<_>>(10);
-/// assert_eq!(parser.parse_peek("xyz"), Ok(("xyz", 10)));
+/// use winnow::combinator::empty;
///
/// fn sign(input: &str) -> IResult<&str, isize> {
/// alt((
/// '-'.value(-1),
/// '+'.value(1),
-/// success::<_,_,InputError<_>>(1)
+/// empty.value(1)
/// )).parse_peek(input)
/// }
/// assert_eq!(sign("+10"), Ok(("10", 1)));
@@ -462,7 +466,13 @@ enum State<E> {
/// assert_eq!(sign("10"), Ok(("10", 1)));
/// ```
#[doc(alias = "value")]
-#[doc(alias = "empty")]
+#[doc(alias = "success")]
+pub fn empty<I: Stream, E: ParserError<I>>(_input: &mut I) -> PResult<(), E> {
+ Ok(())
+}
+
+/// Deprecated, replaced with [`empty`] + [`Parser::value`]
+#[deprecated(since = "0.5.35", note = "Replaced with empty.value(...)`")]
pub fn success<I: Stream, O: Clone, E: ParserError<I>>(val: O) -> impl Parser<I, O, E> {
trace("success", move |_input: &mut I| Ok(val.clone()))
}