Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump rsjsonnet-lang from 0.1.1 to 0.3.0 #14

Merged
merged 3 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 59 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ text_io = "0.1"
aws-config = { version = "1", features = ["behavior-version-latest"] }
aws-sdk-scheduler = { version = "1", features = ["behavior-version-latest"] }
aws-sdk-sfn = { version = "1", features = ["behavior-version-latest"] }
rsjsonnet-front = "0.1"
rsjsonnet-lang = "0.1"
rsjsonnet-front = "0.3"
rsjsonnet-lang = "0.3"
similar = "2"
serde = { version = "1", features = ["derive"] }
serde_json = "1.0"
Expand Down
26 changes: 18 additions & 8 deletions src/jsonnet_evaluator.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,36 @@
use std::path::Path;
use std::{collections::HashSet, path::Path};

use serde_json::Value;

use crate::cli::StrKeyVal;

use rsjsonnet_front::Session;
use rsjsonnet_lang::program::Value as JsonnetValue;

pub fn eval(file_path: &str, ext_str: &[StrKeyVal]) -> Result<Value, String> {
let source_path = Path::new(file_path);

let mut session = rsjsonnet_front::Session::new();
let arena = rsjsonnet_lang::arena::Arena::new();
let mut session = Session::new(&arena);

ext_str.iter().for_each(|ext_str| {
let key = session.program().str_interner().intern(&ext_str.var);
let val = if let Some(val) = &ext_str.val {
let mut ext_names = HashSet::new();

for arg in ext_str.iter() {
let key = session.program().intern_str(&arg.var);
if !ext_names.insert(key) {
let err_msg = format!("External variable {:?} defined more than once", arg.var);
return Err(err_msg);
}

let val = if let Some(val) = &arg.val {
JsonnetValue::string(val.as_ref())
} else {
JsonnetValue::null()
};
let value_thunk = session.program_mut().value_to_thunk(&val);
session.program_mut().add_ext_var(key, &value_thunk);
});

let thunk = session.program_mut().value_to_thunk(&val);
session.program_mut().add_ext_var(key, &thunk);
}

let Some(thunk) = session.load_real_file(source_path) else {
return Err("Failed to load file".to_string());
Expand Down