difftreelog
feat better handling for missing feature errors
in: master
2 files changed
crates/jrsonnet-evaluator/src/error.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/error.rs
+++ b/crates/jrsonnet-evaluator/src/error.rs
@@ -181,10 +181,16 @@
#[error("can't import from virtual file")]
CantImportFromVirtualFile,
#[error(
- "syntax error: expected {}, got {:?}",
- .error.expected,
- .path.code().chars().nth(error.location.offset)
- .map_or_else(|| "EOF".into(), |c| c.to_string())
+ "syntax error: {}",
+ // Peg has no fancier way to handle critical parsing errors https://github.com/kevinmehall/rust-peg/issues/225
+ {.error.expected.tokens().find(|t| t.starts_with("!!!")).map_or_else(|| {
+ format!(
+ "expected {}, got {:?}",
+ .error.expected,
+ .path.code().chars().nth(error.location.offset)
+ .map_or_else(|| "EOF".into(), |c| c.to_string())
+ )
+ }, |v| v[3..].into())}
)]
ImportSyntaxError {
path: Source,
crates/jrsonnet-parser/src/lib.rsdiffbeforeafterboth106 rest: rest.0,106 rest: rest.0,107 end: rest.1,107 end: rest.1,108 });108 });109 #[cfg(not(feature = "exp-destruct"))] Err("experimental destructuring was not enabled")109 #[cfg(not(feature = "exp-destruct"))] Err("!!!experimental destructuring was not enabled")110 }110 }111 pub rule destruct_object(s: &ParserSettings) -> expr::Destruct111 pub rule destruct_object(s: &ParserSettings) -> expr::Destruct112 = "{" _112 = "{" _120 fields,120 fields,121 rest,121 rest,122 });122 });123 #[cfg(not(feature = "exp-destruct"))] Err("experimental destructuring was not enabled")123 #[cfg(not(feature = "exp-destruct"))] Err("!!!experimental destructuring was not enabled")124 }124 }125 pub rule destruct(s: &ParserSettings) -> expr::Destruct125 pub rule destruct(s: &ParserSettings) -> expr::Destruct126 = v:id() {expr::Destruct::Full(v)}126 = v:id() {expr::Destruct::Full(v)}127 / "?" {?127 / "?" {?128 #[cfg(feature = "exp-destruct")] return Ok(expr::Destruct::Skip);128 #[cfg(feature = "exp-destruct")] return Ok(expr::Destruct::Skip);129 #[cfg(not(feature = "exp-destruct"))] Err("experimental destructuring was not enabled")129 #[cfg(not(feature = "exp-destruct"))] Err("!!!experimental destructuring was not enabled")130 }130 }131 / arr:destruct_array(s) {arr}131 / arr:destruct_array(s) {arr}132 / obj:destruct_object(s) {obj}132 / obj:destruct_object(s) {obj}