Skip to content

Commit

Permalink
docs: Reduce reliance on peeking
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Jul 5, 2023
1 parent 071d502 commit 283e6dc
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
32 changes: 16 additions & 16 deletions src/_topic/language.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@
//! token::take_till1,
//! };
//!
//! pub fn peol_comment<'a, E: ParseError<&'a str>>(i: &'a str) -> IResult<&'a str, (), E>
//! pub fn peol_comment<'a, E: ParseError<&'a str>>(i: &mut &'a str) -> PResult<(), E>
//! {
//! ('%', take_till1(['\n', '\r']))
//! .void() // Output is thrown away.
//! .parse_peek(i)
//! .parse_next(i)
//! }
//! ```
//!
Expand All @@ -85,14 +85,14 @@
//! token::{tag, take_until0},
//! };
//!
//! pub fn pinline_comment<'a, E: ParseError<&'a str>>(i: &'a str) -> IResult<&'a str, (), E> {
//! pub fn pinline_comment<'a, E: ParseError<&'a str>>(i: &mut &'a str) -> PResult<(), E> {
//! (
//! "(*",
//! take_until0("*)"),
//! "*)"
//! )
//! .void() // Output is thrown away.
//! .parse_peek(i)
//! .parse_next(i)
//! }
//! ```
//!
Expand All @@ -111,13 +111,13 @@
//! token::one_of,
//! };
//!
//! pub fn identifier(input: &str) -> IResult<&str, &str> {
//! pub fn identifier<'s>(input: &mut &'s str) -> PResult<&'s str> {
//! (
//! one_of(|c: char| c.is_alpha() || c == '_'),
//! take_while(0.., |c: char| c.is_alphanum() || c == '_')
//! )
//! .recognize()
//! .parse_peek(input)
//! .parse_next(input)
//! }
//! ```
//!
Expand Down Expand Up @@ -162,13 +162,13 @@
//! token::tag,
//! };
//!
//! fn hexadecimal(input: &str) -> IResult<&str, &str> { // <'a, E: ParseError<&'a str>>
//! fn hexadecimal<'s>(input: &mut &'s str) -> PResult<&'s str> { // <'a, E: ParseError<&'a str>>
//! preceded(
//! alt(("0x", "0X")),
//! repeat(1..,
//! terminated(one_of(('0'..='9', 'a'..='f', 'A'..='F')), repeat(0.., '_').map(|()| ()))
//! ).map(|()| ()).recognize()
//! ).parse_peek(input)
//! ).parse_next(input)
//! }
//! ```
//!
Expand All @@ -184,15 +184,15 @@
//! token::tag,
//! };
//!
//! fn hexadecimal_value(input: &str) -> IResult<&str, i64> {
//! fn hexadecimal_value(input: &mut &str) -> PResult<i64> {
//! preceded(
//! alt(("0x", "0X")),
//! repeat(1..,
//! terminated(one_of(('0'..='9', 'a'..='f', 'A'..='F')), repeat(0.., '_').map(|()| ()))
//! ).map(|()| ()).recognize()
//! ).try_map(
//! |out: &str| i64::from_str_radix(&str::replace(&out, "_", ""), 16)
//! ).parse_peek(input)
//! ).parse_next(input)
//! }
//! ```
//!
Expand All @@ -210,13 +210,13 @@
//! token::tag,
//! };
//!
//! fn octal(input: &str) -> IResult<&str, &str> {
//! fn octal<'s>(input: &mut &'s str) -> PResult<&'s str> {
//! preceded(
//! alt(("0o", "0O")),
//! repeat(1..,
//! terminated(one_of('0'..='7'), repeat(0.., '_').map(|()| ()))
//! ).map(|()| ()).recognize()
//! ).parse_peek(input)
//! ).parse_next(input)
//! }
//! ```
//!
Expand All @@ -232,13 +232,13 @@
//! token::tag,
//! };
//!
//! fn binary(input: &str) -> IResult<&str, &str> {
//! fn binary<'s>(input: &mut &'s str) -> PResult<&'s str> {
//! preceded(
//! alt(("0b", "0B")),
//! repeat(1..,
//! terminated(one_of('0'..='1'), repeat(0.., '_').map(|()| ()))
//! ).map(|()| ()).recognize()
//! ).parse_peek(input)
//! ).parse_next(input)
//! }
//! ```
//!
Expand All @@ -253,12 +253,12 @@
//! token::one_of,
//! };
//!
//! fn decimal(input: &str) -> IResult<&str, &str> {
//! fn decimal<'s>(input: &mut &'s str) -> PResult<&'s str> {
//! repeat(1..,
//! terminated(one_of('0'..='9'), repeat(0.., '_').map(|()| ()))
//! ).map(|()| ())
//! .recognize()
//! .parse_peek(input)
//! .parse_next(input)
//! }
//! ```
//!
Expand Down
4 changes: 2 additions & 2 deletions src/_topic/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
//! # use winnow::token::tag;
//! # type MyStream<'i> = &'i str;
//! # type Output<'i> = &'i str;
//! fn parser(i: MyStream<'_>) -> IResult<MyStream<'_>, Output<'_>> {
//! "test".parse_peek(i)
//! fn parser<'s>(i: &mut MyStream<'s>) -> PResult<Output<'s>> {
//! "test".parse_next(i)
//! }
//! ```
//!
Expand Down
14 changes: 7 additions & 7 deletions src/trace/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ compile_error!("`debug` requires `std`");
/// # use winnow::prelude::*;
/// use winnow::trace::trace;
///
/// fn short_alpha(s: &[u8]) -> IResult<&[u8], &[u8]> {
/// fn short_alpha<'s>(s: &mut &'s [u8]) -> PResult<&'s [u8], Error<&'s [u8]>> {
/// trace("short_alpha",
/// take_while(3..=6, AsChar::is_alpha)
/// ).parse_peek(s)
/// ).parse_next(s)
/// }
///
/// assert_eq!(short_alpha(b"latin123"), Ok((&b"123"[..], &b"latin"[..])));
/// assert_eq!(short_alpha(b"lengthy"), Ok((&b"y"[..], &b"length"[..])));
/// assert_eq!(short_alpha(b"latin"), Ok((&b""[..], &b"latin"[..])));
/// assert_eq!(short_alpha(b"ed"), Err(ErrMode::Backtrack(Error::new(&b"ed"[..], ErrorKind::Slice))));
/// assert_eq!(short_alpha(b"12345"), Err(ErrMode::Backtrack(Error::new(&b"12345"[..], ErrorKind::Slice))));
/// assert_eq!(short_alpha.parse_peek(b"latin123"), Ok((&b"123"[..], &b"latin"[..])));
/// assert_eq!(short_alpha.parse_peek(b"lengthy"), Ok((&b"y"[..], &b"length"[..])));
/// assert_eq!(short_alpha.parse_peek(b"latin"), Ok((&b""[..], &b"latin"[..])));
/// assert_eq!(short_alpha.parse_peek(b"ed"), Err(ErrMode::Backtrack(Error::new(&b"ed"[..], ErrorKind::Slice))));
/// assert_eq!(short_alpha.parse_peek(b"12345"), Err(ErrMode::Backtrack(Error::new(&b"12345"[..], ErrorKind::Slice))));
/// ```
#[cfg_attr(not(feature = "debug"), allow(unused_variables))]
#[cfg_attr(not(feature = "debug"), allow(unused_mut))]
Expand Down

0 comments on commit 283e6dc

Please sign in to comment.