better sheet error display

This commit is contained in:
Ponj 2024-10-31 14:42:56 -04:00
parent 1c823554da
commit f690d3d286
Signed by: p6nj
GPG key ID: 6FED68D87C479A59

View file

@ -45,18 +45,18 @@ enum AtomsSerializeError {
fn nom_err_message(e: nom::Err<nom::error::Error<&str>>) -> String {
match e {
nom::Err::Incomplete(needed) => todo!(),
nom::Err::Error(e) => format!(
"got error code {code:#?} at character n°{charn} (after \"{before}\")",
code = e.code,
charn = e.input.len() + 1,
before = &e.input[e.input.len()
- option_env!("SHEET_BACKTRACE")
.and_then(|s| s.parse().ok())
.unwrap_or(10usize)
+ 1..]
nom::Err::Incomplete(needed) => format!(
"input is incomplete, needed {} byte(s) more",
match needed {
nom::Needed::Unknown => "?".to_string(),
nom::Needed::Size(s) => s.to_string(),
}
),
nom::Err::Error(e) | nom::Err::Failure(e) => format!(
"got error code {code:#?} at \"{input}\"",
code = e.code,
input = e.input
),
nom::Err::Failure(e) => todo!(),
}
}
@ -127,7 +127,7 @@ impl<'de> Deserialize<'de> for Atoms {
let x = all_consuming(terminated(
many0(preceded(many0(one_of(" \t\r")), flat_atom_parser(&notes))),
many0(alt((char('\t'), char(' '), char('\n'), char('\r')))),
))(dbg!(&sheet))
))(&sheet)
.map_err(nom_err_message)
.map_err(AtomsSerializeError::Parsing)
.map_err(de::Error::custom)