difftreelog
feat(evaluator) add importStr
in: master
2 files changed
crates/jsonnet-evaluator/src/evaluate.rsdiffbeforeafterboth--- a/crates/jsonnet-evaluator/src/evaluate.rs
+++ b/crates/jsonnet-evaluator/src/evaluate.rs
@@ -1,6 +1,7 @@
use crate::{
context_creator, create_error, future_wrapper, lazy_val, push, with_state, Context,
ContextCreator, Error, FuncDesc, LazyBinding, LazyVal, ObjMember, ObjValue, Result, Val,
+ ValType,
};
use closure::closure;
use jsonnet_parser::{
@@ -726,9 +727,15 @@
lib_path.push(path);
with_state(|s| s.import_file(&lib_path))?
}
- _ => panic!(
- "evaluation not implemented: {:?}",
- LocExpr(expr.clone(), loc.clone())
- ),
+ ImportStr(path) => {
+ let mut file_path = loc
+ .clone()
+ .expect("imports can't be used without loc_data")
+ .0
+ .clone();
+ file_path.pop();
+ file_path.push(path);
+ Val::Str(with_state(|s| s.import_file_str(&file_path))?)
+ }
})
}
crates/jsonnet-evaluator/src/lib.rsdiffbeforeafterboth68 /// Contains file source codes and evaluated results for imports and pretty68 /// Contains file source codes and evaluated results for imports and pretty69 /// printing stacktraces69 /// printing stacktraces70 files: RefCell<HashMap<PathBuf, FileData>>,70 files: RefCell<HashMap<PathBuf, FileData>>,71 str_files: RefCell<HashMap<PathBuf, String>>,71 globals: RefCell<HashMap<String, Val>>,72 globals: RefCell<HashMap<String, Val>>,727373 /// Values to use with std.extVar74 /// Values to use with std.extVar177 }178 }178 self.evaluate_file_in_current_state(path)179 self.evaluate_file_in_current_state(path)179 }180 }181 pub(crate) fn import_file_str(&self, path: &PathBuf) -> Result<String> {182 if !self.0.str_files.borrow().contains_key(path) {183 let file_str = (self.0.settings.import_resolver)(path);184 self.0.str_files.borrow_mut().insert(path.clone(), file_str);185 }186 Ok(self.0.str_files.borrow().get(path).cloned().unwrap())187 }180188181 pub fn parse_evaluate_raw(&self, code: &str) -> Result<Val> {189 pub fn parse_evaluate_raw(&self, code: &str) -> Result<Val> {182 let parsed = parse(190 let parsed = parse(