better sheet error display

This commit is contained in:
Breval Ferrari 2024-10-31 14:42:56 -04:00
parent 1c823554da
commit f690d3d286
No known key found for this signature in database
GPG key ID: 6FED68D87C479A59

View file

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