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

difftreelog

feat support legacy std.thisFile

Yaroslav Bolyukin2022-04-22parent: #e082575.patch.diff
in: master

5 files changed

modifiedcrates/jrsonnet-evaluator/src/error.rsdiffbeforeafterboth
140 #[error("sort error: {0}")]140 #[error("sort error: {0}")]
141 Sort(#[from] SortError),141 Sort(#[from] SortError),
142
143 /// Thrown as error, as this is legacy feature, and error here
144 /// is acceptable for defeating object field cache
145 #[error("should not reach outside: std.thisFile")]
146 MagicThisFileUsed,
142147
143 #[cfg(feature = "anyhow-error")]148 #[cfg(feature = "anyhow-error")]
144 #[error(transparent)]149 #[error(transparent)]
modifiedcrates/jrsonnet-evaluator/src/evaluate/mod.rsdiffbeforeafterboth
568 (Val::Obj(v), Val::Str(key)) => s.push(568 (Val::Obj(v), Val::Str(key)) => s.push(
569 CallLocation::new(loc),569 CallLocation::new(loc),
570 || format!("field <{}> access", key),570 || format!("field <{}> access", key),
571 || {571 || match v.get(s.clone(), key.clone()) {
572 if let Some(v) = v.get(s.clone(), key.clone())? {
573 Ok(v)572 Ok(Some(v)) => Ok(v),
574 } else {
575 throw!(NoSuchField(key.clone()))573 Ok(None) => throw!(NoSuchField(key.clone())),
576 }574 Err(e) if matches!(e.error(), MagicThisFileUsed) => {
577 },575 Ok(Val::Str(loc.0.to_string_lossy().into()))
576 }
577 Err(e) => Err(e),
578 },
578 )?,579 )?,
579 (Val::Obj(_), n) => throw!(ValueIndexMustBeTypeGot(580 (Val::Obj(_), n) => throw!(ValueIndexMustBeTypeGot(
580 ValType::Obj,581 ValType::Obj,
674 .with(|b| b.get(name).copied())675 .with(|b| b.get(name).copied())
675 .ok_or_else(|| IntrinsicNotFound(name.clone()))?,676 .ok_or_else(|| IntrinsicNotFound(name.clone()))?,
676 )),677 )),
678 IntrinsicThisFile => return Err(MagicThisFileUsed.into()),
677 AssertExpr(assert, returned) => {679 AssertExpr(assert, returned) => {
678 evaluate_assert(s.clone(), ctx.clone(), assert)?;680 evaluate_assert(s.clone(), ctx.clone(), assert)?;
679 evaluate(s, ctx, returned)?681 evaluate(s, ctx, returned)?
modifiedcrates/jrsonnet-parser/src/expr.rsdiffbeforeafterboth
296 Index(LocExpr, LocExpr),296 Index(LocExpr, LocExpr),
297 /// function(x) x297 /// function(x) x
298 Function(ParamsDesc, LocExpr),298 Function(ParamsDesc, LocExpr),
299 /// std.thisFile
300 IntrinsicThisFile,
299 /// std.primitiveEquals301 /// std.primitiveEquals
300 Intrinsic(IStr),302 Intrinsic(IStr),
301 /// if true == false then 1 else 2303 /// if true == false then 1 else 2
modifiedcrates/jrsonnet-parser/src/lib.rsdiffbeforeafterboth
210 pub rule expr_basic(s: &ParserSettings) -> Expr210 pub rule expr_basic(s: &ParserSettings) -> Expr
211 = literal(s)211 = literal(s)
212212
213 / quiet!{"$intrinsic(" name:$(id()) ")" {Expr::Intrinsic(name.into())}}213 / quiet!{"$intrinsicThisFile" {Expr::IntrinsicThisFile}}
214 / quiet!{"$intrinsic(" name:$(id()) ")" {Expr::Intrinsic(name.into())}}
214215
215 / string_expr(s) / number_expr(s)216 / string_expr(s) / number_expr(s)
216 / array_expr(s)217 / array_expr(s)
modifiedcrates/jrsonnet-stdlib/src/std.jsonnetdiffbeforeafterboth
2 local std = self,2 local std = self,
3 local id = std.id,3 local id = std.id,
44
5 # Magic legacy field
6 thisFile:: $intrinsicThisFile,
7
5 # Those functions aren't normally located in stdlib8 # Those functions aren't normally located in stdlib
6 length:: $intrinsic(length),9 length:: $intrinsic(length),
7 type:: $intrinsic(type),10 type:: $intrinsic(type),