Skip to content

Commit

Permalink
Merge pull request #749 from epage/tut
Browse files Browse the repository at this point in the history
docs(tutorial): Clear up suggestions on spans
  • Loading branch information
epage authored Feb 22, 2025
2 parents d6e7bbb + 60c574e commit 70e1f43
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/_tutorial/chapter_7.rs
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@
//! # })
//! # .map(Hex)
//! .parse(input)
//! .map_err(|e| HexError::from_parse(e, input))
//! .map_err(|e| HexError::from_parse(e))
//! }
//! }
//!
Expand All @@ -620,13 +620,13 @@
//! }
//!
//! impl HexError {
//! fn from_parse(error: ParseError<&str, ContextError>, input: &str) -> Self {
//! // Avoiding `From` so `winnow` types don't become part of our public API
//! fn from_parse(error: ParseError<&str, ContextError>) -> Self {
//! // The default renderer for `ContextError` is still used but that can be
//! // customized as well to better fit your needs.
//! let message = error.inner().to_string();
//! let input = input.to_owned();
//! let input = (*error.input()).to_owned();
//! // Assume the error span is only for the first `char`.
//! // Semantic errors are free to choose the entire span returned by `Parser::with_span`.
//! let span = error.char_span();
//! Self {
//! message,
Expand Down Expand Up @@ -711,6 +711,11 @@
//! assert_eq!(input.parse::<Hex>().unwrap_err().to_string(), error);
//! }
//! ```
//!
//! To add spans to your parsed data for inclusion in semantic errors, see [`Parser::with_span`].
//!
//! For richer syntactic with spans,
//! consider separating lexing and parsing and annotating your tokens with [`Parser::with_span`].
#![allow(unused_imports)]
use super::chapter_1;
Expand Down

0 comments on commit 70e1f43

Please sign in to comment.