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

difftreelog

fix parser should parse import argument as an expression

Yaroslav Bolyukin2022-11-10parent: #8d4d5b7.patch.diff
in: master

4 files changed

modifiedcrates/jrsonnet-evaluator/src/evaluate/mod.rsdiffbeforeafterboth
17 tb, throw,17 tb, throw,
18 typed::Typed,18 typed::Typed,
19 val::{ArrValue, CachedUnbound, IndexableVal, Thunk, ThunkValue},19 val::{ArrValue, CachedUnbound, IndexableVal, Thunk, ThunkValue},
20 Context, GcHashMap, ObjValue, ObjValueBuilder, ObjectAssertion, Pending, Result, State,20 Context, GcHashMap, LocError, ObjValue, ObjValueBuilder, ObjectAssertion, Pending, Result,
21 Unbound, Val,21 ResultExt, State, Unbound, Val,
22};22};
23pub mod destructure;23pub mod destructure;
24pub mod operator;24pub mod operator;
591 IndexableVal::into_untyped(indexable.into_indexable()?.slice(start, end, step)?)?591 IndexableVal::into_untyped(indexable.into_indexable()?.slice(start, end, step)?)?
592 }592 }
593 i @ (Import(path) | ImportStr(path) | ImportBin(path)) => {593 i @ (Import(path) | ImportStr(path) | ImportBin(path)) => {
594 let Expr::Str(path) = &*path.0 else {
595 throw!("computed imports are not supported")
596 };
594 let tmp = loc.clone().0;597 let tmp = loc.clone().0;
595 let s = ctx.state();598 let s = ctx.state();
596 let resolved_path = s.resolve_from(tmp.source_path(), path as &str)?;599 let resolved_path = s.resolve_from(tmp.source_path(), path as &str)?;
modifiedcrates/jrsonnet-evaluator/src/tla.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/tla.rs
+++ b/crates/jrsonnet-evaluator/src/tla.rs
@@ -12,7 +12,10 @@
 			|| "during TLA call".to_owned(),
 			|| {
 				func.evaluate(
-					s.create_default_context(Source::new_virtual("<top-level-arg>".into(), IStr::empty())),
+					s.create_default_context(Source::new_virtual(
+						"<top-level-arg>".into(),
+						IStr::empty(),
+					)),
 					CallLocation::native(),
 					args,
 					false,
modifiedcrates/jrsonnet-parser/src/expr.rsdiffbeforeafterboth
--- a/crates/jrsonnet-parser/src/expr.rs
+++ b/crates/jrsonnet-parser/src/expr.rs
@@ -390,11 +390,11 @@
 	LocalExpr(Vec<BindSpec>, LocExpr),
 
 	/// import "hello"
-	Import(IStr),
+	Import(LocExpr),
 	/// importStr "file.txt"
-	ImportStr(IStr),
+	ImportStr(LocExpr),
 	/// importBin "file.txt"
-	ImportBin(IStr),
+	ImportBin(LocExpr),
 	/// error "I'm broken"
 	ErrorStmt(LocExpr),
 	/// a(b, c)
modifiedcrates/jrsonnet-parser/src/lib.rsdiffbeforeafterboth
--- a/crates/jrsonnet-parser/src/lib.rs
+++ b/crates/jrsonnet-parser/src/lib.rs
@@ -257,9 +257,9 @@
 			/ array_expr(s)
 			/ array_comp_expr(s)
 
-			/ keyword("importstr") _ path:string() {Expr::ImportStr(path.into())}
-			/ keyword("importbin") _ path:string() {Expr::ImportBin(path.into())}
-			/ keyword("import") _ path:string() {Expr::Import(path.into())}
+			/ keyword("importstr") _ path:expr(s) {Expr::ImportStr(path)}
+			/ keyword("importbin") _ path:expr(s) {Expr::ImportBin(path)}
+			/ keyword("import") _ path:expr(s) {Expr::Import(path)}
 
 			/ var_expr(s)
 			/ local_expr(s)