difftreelog
fix parser should parse import argument as an expression
in: master
4 files changed
crates/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)?;
crates/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,
crates/jrsonnet-parser/src/expr.rsdiffbeforeafterboth390 LocalExpr(Vec<BindSpec>, LocExpr),390 LocalExpr(Vec<BindSpec>, LocExpr),391391392 /// import "hello"392 /// import "hello"393 Import(IStr),393 Import(LocExpr),394 /// importStr "file.txt"394 /// importStr "file.txt"395 ImportStr(IStr),395 ImportStr(LocExpr),396 /// importBin "file.txt"396 /// importBin "file.txt"397 ImportBin(IStr),397 ImportBin(LocExpr),398 /// error "I'm broken"398 /// error "I'm broken"399 ErrorStmt(LocExpr),399 ErrorStmt(LocExpr),400 /// a(b, c)400 /// a(b, c)crates/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)