feat(tvix/eval): Support builtins.substring

Nix's `builtins.substring`:
- doesn't accept negative indexes for `beg` or `end`. Compare the error messages
  for:
  - `builtins.substring -3  5 "testing"`
  - `builtins.substring  3 -5 "testing"`
  - `builtins.substring -3 -5 "testing"`
- returns an empty string when `beg >= end`
- allows `end` to exceed the length of the input string

Change-Id: I83af7a099d81b6d537ebe5029d946c7031cb7113
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6555
Reviewed-by: wpcarro <wpcarro@gmail.com>
Autosubmit: wpcarro <wpcarro@gmail.com>
Reviewed-by: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
This commit is contained in:
William Carroll 2022-09-06 14:33:10 -07:00 committed by clbot
parent 0c75ce2d3d
commit 2fe18e4486
4 changed files with 61 additions and 0 deletions

View file

@ -80,6 +80,11 @@ pub enum ErrorKind {
/// An error occurred when parsing an integer
ParseIntError(ParseIntError),
/// A negative integer was used as a value representing length.
NegativeLength {
length: i64,
},
/// Tvix internal warning for features triggered by users that are
/// not actually implemented yet, and without which eval can not
/// proceed.
@ -213,6 +218,13 @@ to a missing value in the attribute set(s) included via `with`."#,
format!("invalid integer: {}", err)
}
ErrorKind::NegativeLength { length } => {
format!(
"cannot use a negative integer, {}, for a value representing length",
length
)
}
ErrorKind::NotImplemented(feature) => {
format!("feature not yet implemented in Tvix: {}", feature)
}
@ -244,6 +256,7 @@ to a missing value in the attribute set(s) included via `with`."#,
ErrorKind::IndexOutOfBounds { .. } => "E019",
ErrorKind::NotAnAbsolutePath(_) => "E020",
ErrorKind::ParseIntError(_) => "E021",
ErrorKind::NegativeLength { .. } => "E022",
ErrorKind::NotImplemented(_) => "E999",
}
}