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
--- a/crates/jrsonnet-evaluator/src/evaluate/mod.rs
+++ b/crates/jrsonnet-evaluator/src/evaluate/mod.rs
@@ -17,8 +17,8 @@
 	tb, throw,
 	typed::Typed,
 	val::{ArrValue, CachedUnbound, IndexableVal, Thunk, ThunkValue},
-	Context, GcHashMap, ObjValue, ObjValueBuilder, ObjectAssertion, Pending, Result, State,
-	Unbound, Val,
+	Context, GcHashMap, LocError, ObjValue, ObjValueBuilder, ObjectAssertion, Pending, Result,
+	ResultExt, State, Unbound, Val,
 };
 pub mod destructure;
 pub mod operator;
@@ -591,6 +591,9 @@
 			IndexableVal::into_untyped(indexable.into_indexable()?.slice(start, end, step)?)?
 		}
 		i @ (Import(path) | ImportStr(path) | ImportBin(path)) => {
+			let Expr::Str(path) = &*path.0 else {
+				throw!("computed imports are not supported")
+			};
 			let tmp = loc.clone().0;
 			let s = ctx.state();
 			let resolved_path = s.resolve_from(tmp.source_path(), path as &str)?;
modifiedcrates/jrsonnet-evaluator/src/tla.rsdiffbeforeafterboth
before · crates/jrsonnet-evaluator/src/tla.rs
1use jrsonnet_interner::IStr;2use jrsonnet_parser::Source;34use crate::{5	function::{ArgsLike, CallLocation},6	Result, State, Val,7};89pub fn apply_tla<A: ArgsLike>(s: State, args: &A, val: Val) -> Result<Val> {10	Ok(if let Val::Func(func) = val {11		State::push_description(12			|| "during TLA call".to_owned(),13			|| {14				func.evaluate(15					s.create_default_context(Source::new_virtual("<top-level-arg>".into(), IStr::empty())),16					CallLocation::native(),17					args,18					false,19				)20			},21		)?22	} else {23		val24	})25}
after · crates/jrsonnet-evaluator/src/tla.rs
1use jrsonnet_interner::IStr;2use jrsonnet_parser::Source;34use crate::{5	function::{ArgsLike, CallLocation},6	Result, State, Val,7};89pub fn apply_tla<A: ArgsLike>(s: State, args: &A, val: Val) -> Result<Val> {10	Ok(if let Val::Func(func) = val {11		State::push_description(12			|| "during TLA call".to_owned(),13			|| {14				func.evaluate(15					s.create_default_context(Source::new_virtual(16						"<top-level-arg>".into(),17						IStr::empty(),18					)),19					CallLocation::native(),20					args,21					false,22				)23			},24		)?25	} else {26		val27	})28}
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)