From 3302e3817ff5d56f5e9233e5901406dea10570c1 Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Wed, 26 Jul 2023 17:19:13 +0000 Subject: [PATCH] feat: better handling for missing feature errors --- --- 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, --- a/crates/jrsonnet-parser/src/lib.rs +++ b/crates/jrsonnet-parser/src/lib.rs @@ -106,7 +106,7 @@ rest: rest.0, end: rest.1, }); - #[cfg(not(feature = "exp-destruct"))] Err("experimental destructuring was not enabled") + #[cfg(not(feature = "exp-destruct"))] Err("!!!experimental destructuring was not enabled") } pub rule destruct_object(s: &ParserSettings) -> expr::Destruct = "{" _ @@ -120,13 +120,13 @@ fields, rest, }); - #[cfg(not(feature = "exp-destruct"))] Err("experimental destructuring was not enabled") + #[cfg(not(feature = "exp-destruct"))] Err("!!!experimental destructuring was not enabled") } pub rule destruct(s: &ParserSettings) -> expr::Destruct = v:id() {expr::Destruct::Full(v)} / "?" {? #[cfg(feature = "exp-destruct")] return Ok(expr::Destruct::Skip); - #[cfg(not(feature = "exp-destruct"))] Err("experimental destructuring was not enabled") + #[cfg(not(feature = "exp-destruct"))] Err("!!!experimental destructuring was not enabled") } / arr:destruct_array(s) {arr} / obj:destruct_object(s) {obj} -- gitstuff