diff options
Diffstat (limited to 'vendor/winnow/src/trace')
-rw-r--r-- | vendor/winnow/src/trace/internals.rs | 12 | ||||
-rw-r--r-- | vendor/winnow/src/trace/mod.rs | 29 |
2 files changed, 15 insertions, 26 deletions
diff --git a/vendor/winnow/src/trace/internals.rs b/vendor/winnow/src/trace/internals.rs index 3a10204b7..b990ae7c7 100644 --- a/vendor/winnow/src/trace/internals.rs +++ b/vendor/winnow/src/trace/internals.rs @@ -87,17 +87,13 @@ pub fn start<I: Stream>( }; let call_column = format!("{:depth$}> {name}{count}", ""); - let eof_offset = input.eof_offset(); - let offset = input.offset_at(input_width).unwrap_or(eof_offset); - let (_, slice) = input.next_slice(offset); - // The debug version of `slice` might be wider, either due to rendering one byte as two nibbles or // escaping in strings. - let mut debug_slice = format!("{:#?}", slice); + let mut debug_slice = format!("{:#?}", input.raw()); let (debug_slice, eof) = if let Some(debug_offset) = debug_slice .char_indices() .enumerate() - .find_map(|(pos, (offset, _))| (input_width <= pos).then(|| offset)) + .find_map(|(pos, (offset, _))| (input_width <= pos).then_some(offset)) { debug_slice.truncate(debug_offset); let eof = ""; @@ -129,7 +125,7 @@ pub fn end( depth: usize, name: &dyn crate::lib::std::fmt::Display, count: usize, - consumed: Option<usize>, + consumed: usize, severity: Severity, ) { let gutter_style = anstyle::Style::new().bold(); @@ -146,7 +142,7 @@ pub fn end( let (status_style, status) = match severity { Severity::Success => { let style = anstyle::Style::new().fg_color(Some(anstyle::AnsiColor::Green.into())); - let status = format!("+{}", consumed.unwrap_or_default()); + let status = format!("+{}", consumed); (style, status) } Severity::Backtrack => ( diff --git a/vendor/winnow/src/trace/mod.rs b/vendor/winnow/src/trace/mod.rs index e5eaf9451..316733e9a 100644 --- a/vendor/winnow/src/trace/mod.rs +++ b/vendor/winnow/src/trace/mod.rs @@ -26,23 +26,23 @@ compile_error!("`debug` requires `std`"); /// # Example /// /// ```rust -/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, error::Needed, IResult}; +/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed}; /// # use winnow::token::take_while; /// # use winnow::stream::AsChar; /// # 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], InputError<&'s [u8]>> { /// trace("short_alpha", /// take_while(3..=6, AsChar::is_alpha) /// ).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(InputError::new(&b"ed"[..], ErrorKind::Slice)))); +/// assert_eq!(short_alpha.parse_peek(b"12345"), Err(ErrMode::Backtrack(InputError::new(&b"12345"[..], ErrorKind::Slice)))); /// ``` #[cfg_attr(not(feature = "debug"), allow(unused_variables))] #[cfg_attr(not(feature = "debug"), allow(unused_mut))] @@ -54,21 +54,14 @@ pub fn trace<I: Stream, O, E>( #[cfg(feature = "debug")] { let mut call_count = 0; - move |i: I| { + move |i: &mut I| { let depth = internals::Depth::new(); - let original = i.clone(); - internals::start(*depth, &name, call_count, &original); + let original = i.checkpoint(); + internals::start(*depth, &name, call_count, i); let res = parser.parse_next(i); - let consumed = res.as_ref().ok().map(|(i, _)| { - if i.eof_offset() == 0 { - // Sometimes, an unrelated empty string is returned which can break `offset_to` - original.eof_offset() - } else { - original.offset_to(i) - } - }); + let consumed = i.offset_from(&original); let severity = internals::Severity::with_result(&res); internals::end(*depth, &name, call_count, consumed, severity); call_count += 1; |