--- a/crates/jrsonnet-evaluator/Cargo.toml +++ b/crates/jrsonnet-evaluator/Cargo.toml @@ -31,7 +31,6 @@ pathdiff = "0.2.0" closure = "0.3.0" -indexmap = "1.6" md5 = "0.7.0" base64 = "0.13.0" --- a/crates/jrsonnet-evaluator/src/builtin/mod.rs +++ b/crates/jrsonnet-evaluator/src/builtin/mod.rs @@ -585,8 +585,7 @@ name: &str, args: &ArgsDesc, ) -> Result { - if let Some(f) = BUILTINS.with(|builtins| builtins.get(name).copied()) { - return Ok(f(context, loc, args)?); - } - throw!(IntrinsicNotFound(name.into())) + BUILTINS.with(|builtins| builtins.get(name).copied()).ok_or_else(|| + IntrinsicNotFound(name.into()) + )?(context, loc, args) } --- a/crates/jrsonnet-evaluator/src/evaluate.rs +++ b/crates/jrsonnet-evaluator/src/evaluate.rs @@ -222,12 +222,12 @@ let future_this = FutureObjValue::new(); let context_creator = context_creator!( closure!(clone context, clone new_bindings, |this: Option, super_obj: Option| { - Ok(context.clone().extend_unbound( + context.clone().extend_unbound( new_bindings.clone().unwrap(), context.dollar().clone().or_else(||this.clone()), Some(this.unwrap()), super_obj - )?) + ) }) ); { @@ -327,12 +327,12 @@ let new_bindings = FutureNewBindings::new(); let context_creator = context_creator!( closure!(clone context, clone new_bindings, |this: Option, super_obj: Option| { - Ok(context.clone().extend_unbound( + context.clone().extend_unbound( new_bindings.clone().unwrap(), context.dollar().clone().or_else(||this.clone()), None, super_obj - )?) + ) }) ); let mut bindings: HashMap = HashMap::new(); @@ -439,7 +439,7 @@ Var(name) => push( loc.as_ref(), || format!("variable <{}>", name), - || Ok(context.binding(name.clone())?.evaluate()?), + || context.binding(name.clone())?.evaluate(), )?, Index(value, index) => { match (evaluate(context.clone(), value)?, evaluate(context, index)?) { --- a/crates/jrsonnet-evaluator/src/lib.rs +++ b/crates/jrsonnet-evaluator/src/lib.rs @@ -344,11 +344,11 @@ None, || "during TLA call".to_owned(), || { - Ok(func.evaluate_map( + func.evaluate_map( self.create_default_context()?, &self.settings().tla_vars, true, - )?) + ) }, )?, v => v, @@ -432,7 +432,7 @@ Ok(self.settings().import_resolver.resolve_file(from, path)?) } pub fn load_file_contents(&self, path: &PathBuf) -> Result { - Ok(self.settings().import_resolver.load_file_contents(path)?) + self.settings().import_resolver.load_file_contents(path) } pub fn import_resolver(&self) -> Ref { @@ -548,8 +548,8 @@ .to_json(0) .unwrap() .replace("\n", "") - }) - }}; + }) + }}; } /// Asserts given code returns `true` --- a/crates/jrsonnet-evaluator/src/typed.rs +++ b/crates/jrsonnet-evaluator/src/typed.rs @@ -16,8 +16,8 @@ match $value { $match(v) => v, _ => unreachable!(), - } - }}; + } + }}; } #[derive(Debug, Error, Clone)] @@ -177,7 +177,7 @@ None, || format!("array index {}", i), || ValuePathItem::Index(i as u64), - || Ok(elem_type.check(&item.clone()?)?), + || elem_type.check(&item.clone()?), )?; } Ok(()) @@ -191,7 +191,7 @@ None, || format!("array index {}", i), || ValuePathItem::Index(i as u64), - || Ok(elem_type.check(&item.clone()?)?), + || elem_type.check(&item.clone()?), )?; } Ok(()) --- a/crates/jrsonnet-evaluator/src/val.rs +++ b/crates/jrsonnet-evaluator/src/val.rs @@ -343,7 +343,7 @@ match $e { $p => $r, _ => panic!("no match"), - } + } }; } impl Val { @@ -537,7 +537,7 @@ let ctx = s .create_default_context()? .with_var("__tmp__to_json__".into(), self.clone()); - Ok(evaluate( + evaluate( ctx, &el!(Expr::Apply( el!(Expr::Index( @@ -558,7 +558,7 @@ false )), )? - .try_cast_str("to json")?) + .try_cast_str("to json") }) } } --- a/crates/jrsonnet-parser/src/expr.rs +++ b/crates/jrsonnet-parser/src/expr.rs @@ -32,6 +32,12 @@ Unhide, } +impl Visibility { + pub fn is_visible(&self) -> bool { + matches!(self, Self::Normal | Self::Unhide) + } +} + #[cfg_attr(feature = "serialize", derive(Serialize))] #[cfg_attr(feature = "deserialize", derive(Deserialize))] #[derive(Debug, PartialEq)] @@ -337,8 +343,8 @@ Some(ExprLocation($name, $start, $end)) } else { None - }, - ) + }, + ) }; } --- a/crates/jrsonnet-parser/src/lib.rs +++ b/crates/jrsonnet-parser/src/lib.rs @@ -319,8 +319,8 @@ &ParserSettings { loc_data: false, file_name: Rc::new(PathBuf::from("/test.jsonnet")), - }, - ) + }, + ) .unwrap() }; }