Skip to content

Commit 8ec1af0

Browse files
committed
feat: feature-gate regex
1 parent 103c2a5 commit 8ec1af0

File tree

3 files changed

+9
-12
lines changed

3 files changed

+9
-12
lines changed

cmds/jrsonnet/Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ exp-object-iteration = ["jrsonnet-evaluator/exp-object-iteration"]
3030
# Bigint type
3131
exp-bigint = ["jrsonnet-evaluator/exp-bigint", "jrsonnet-cli/exp-bigint"]
3232
# std.regex and co.
33-
exp-regex = [
34-
"jrsonnet-stdlib/exp-regex",
35-
]
33+
exp-regex = ["jrsonnet-cli/exp-regex"]
3634
# obj?.field, obj?.['field']
3735
exp-null-coaelse = [
3836
"jrsonnet-evaluator/exp-null-coaelse",

crates/jrsonnet-evaluator/src/typed/conversions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::{
1010
bail,
1111
function::{native::NativeDesc, FuncDesc, FuncVal},
1212
typed::CheckType,
13-
val::{IndexableVal, ThunkMapper},
13+
val::{IndexableVal, StrValue, ThunkMapper},
1414
ObjValue, ObjValueBuilder, Result, Thunk, Val,
1515
};
1616

crates/jrsonnet-stdlib/src/regex.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub fn regex_match_inner(regex: &Regex, str: String) -> Result<Val> {
4545
let mut named_captures = ObjValueBuilder::with_capacity(regex.capture_names().len());
4646

4747
let Some(captured) = regex.captures(&str) else {
48-
return Ok(Val::Null)
48+
return Ok(Val::Null);
4949
};
5050

5151
for ele in captured.iter().skip(1) {
@@ -62,15 +62,14 @@ pub fn regex_match_inner(regex: &Regex, str: String) -> Result<Val> {
6262
.flat_map(|(i, v)| Some((i, v?)))
6363
{
6464
let capture = captures[i].clone();
65-
named_captures.member(name.into()).value(capture)?;
65+
named_captures.field(name).try_value(capture)?;
6666
}
6767

68-
out.member("string".into())
69-
.value_unchecked(Val::Str(captured.get(0).unwrap().as_str().into()));
70-
out.member("captures".into())
71-
.value_unchecked(Val::Arr(captures.into()));
72-
out.member("namedCaptures".into())
73-
.value_unchecked(Val::Obj(named_captures.build()));
68+
out.field("string")
69+
.value(Val::Str(captured.get(0).unwrap().as_str().into()));
70+
out.field("captures").value(Val::Arr(captures.into()));
71+
out.field("namedCaptures")
72+
.value(Val::Obj(named_captures.build()));
7473

7574
Ok(Val::Obj(out.build()))
7675
}

0 commit comments

Comments
 (0)