| 1 |
//! # Chapter 8: Debugging |
| 2 |
//! |
| 3 |
//! When things inevitably go wrong, you can introspect the parsing state by running your test case |
| 4 |
//! with `--features winnow/debug`. |
| 5 |
//! |
| 6 |
//! For example, the trace output of an [escaped string parser][crate::_topic::language#escaped-strings]: |
| 7 |
//!  |
| 8 |
//! |
| 9 |
//! You can extend your own parsers to show up by wrapping their body with |
| 10 |
//! [`trace`][crate::combinator::trace]. Going back to [`do_nothing_parser`][super::chapter_1]. |
| 11 |
//! ```rust |
| 12 |
//! # use winnow::ModalResult; |
| 13 |
//! # use winnow::Parser; |
| 14 |
//! use winnow::combinator::trace; |
| 15 |
//! |
| 16 |
//! pub fn do_nothing_parser<'s>(input: &mut &'s str) -> ModalResult<&'s str> { |
| 17 |
//! trace( |
| 18 |
//! "do_nothing_parser", |
| 19 |
//! |i: &mut _| Ok("") |
| 20 |
//! ).parse_next(input) |
| 21 |
//! } |
| 22 |
//! # |
| 23 |
//! # fn main() { |
| 24 |
//! # let mut input = "0x1a2b Hello"; |
| 25 |
//! # |
| 26 |
//! # let output = do_nothing_parser.parse_next(&mut input).unwrap(); |
| 27 |
//! # // Same as: |
| 28 |
//! # // let output = do_nothing_parser(&mut input).unwrap(); |
| 29 |
//! # |
| 30 |
//! # assert_eq!(input, "0x1a2b Hello"); |
| 31 |
//! # assert_eq!(output, ""); |
| 32 |
//! # } |
| 33 |
//! ``` |
| 34 |
|
| 35 |
pub use super::chapter_7 as previous; |
| 36 |
pub use crate::_topic as next; |
| 37 |
pub use crate::_tutorial as table_of_contents; |