git.delta.rocks / jrsonnet / refs/commits / f42e5e7a70ee

difftreelog

feat(evaluator) add importStr

Лач2020-06-14parent: #d84b1e9.patch.diff
in: master

2 files changed

modifiedcrates/jsonnet-evaluator/src/evaluate.rsdiffbeforeafterboth
1use crate::{1use crate::{
2 context_creator, create_error, future_wrapper, lazy_val, push, with_state, Context,2 context_creator, create_error, future_wrapper, lazy_val, push, with_state, Context,
3 ContextCreator, Error, FuncDesc, LazyBinding, LazyVal, ObjMember, ObjValue, Result, Val,3 ContextCreator, Error, FuncDesc, LazyBinding, LazyVal, ObjMember, ObjValue, Result, Val,
4 ValType,
4};5};
5use closure::closure;6use closure::closure;
6use jsonnet_parser::{7use jsonnet_parser::{
726 lib_path.push(path);727 lib_path.push(path);
727 with_state(|s| s.import_file(&lib_path))?728 with_state(|s| s.import_file(&lib_path))?
728 }729 }
729 _ => panic!(730 ImportStr(path) => {
730 "evaluation not implemented: {:?}",731 let mut file_path = loc
731 LocExpr(expr.clone(), loc.clone())732 .clone()
732 ),733 .expect("imports can't be used without loc_data")
734 .0
735 .clone();
736 file_path.pop();
737 file_path.push(path);
738 Val::Str(with_state(|s| s.import_file_str(&file_path))?)
739 }
733 })740 })
734}741}
735742
modifiedcrates/jsonnet-evaluator/src/lib.rsdiffbeforeafterboth
68 /// Contains file source codes and evaluated results for imports and pretty68 /// Contains file source codes and evaluated results for imports and pretty
69 /// printing stacktraces69 /// printing stacktraces
70 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>>,
7273
73 /// Values to use with std.extVar74 /// Values to use with std.extVar
177 }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 }
180188
181 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(