Skip to content

Commit

Permalink
feat: feature-gate regex
Browse files Browse the repository at this point in the history
  • Loading branch information
CertainLach committed Dec 10, 2023
1 parent 103c2a5 commit 8ec1af0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
4 changes: 1 addition & 3 deletions cmds/jrsonnet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ exp-object-iteration = ["jrsonnet-evaluator/exp-object-iteration"]
# Bigint type
exp-bigint = ["jrsonnet-evaluator/exp-bigint", "jrsonnet-cli/exp-bigint"]
# std.regex and co.
exp-regex = [
"jrsonnet-stdlib/exp-regex",
]
exp-regex = ["jrsonnet-cli/exp-regex"]
# obj?.field, obj?.['field']
exp-null-coaelse = [
"jrsonnet-evaluator/exp-null-coaelse",
Expand Down
2 changes: 1 addition & 1 deletion crates/jrsonnet-evaluator/src/typed/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
bail,
function::{native::NativeDesc, FuncDesc, FuncVal},
typed::CheckType,
val::{IndexableVal, ThunkMapper},
val::{IndexableVal, StrValue, ThunkMapper},
ObjValue, ObjValueBuilder, Result, Thunk, Val,
};

Expand Down
15 changes: 7 additions & 8 deletions crates/jrsonnet-stdlib/src/regex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub fn regex_match_inner(regex: &Regex, str: String) -> Result<Val> {
let mut named_captures = ObjValueBuilder::with_capacity(regex.capture_names().len());

let Some(captured) = regex.captures(&str) else {
return Ok(Val::Null)
return Ok(Val::Null);
};

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

out.member("string".into())
.value_unchecked(Val::Str(captured.get(0).unwrap().as_str().into()));
out.member("captures".into())
.value_unchecked(Val::Arr(captures.into()));
out.member("namedCaptures".into())
.value_unchecked(Val::Obj(named_captures.build()));
out.field("string")
.value(Val::Str(captured.get(0).unwrap().as_str().into()));
out.field("captures").value(Val::Arr(captures.into()));
out.field("namedCaptures")
.value(Val::Obj(named_captures.build()));

Ok(Val::Obj(out.build()))
}
Expand Down

0 comments on commit 8ec1af0

Please sign in to comment.