diff --git a/Cargo.lock b/Cargo.lock index 6a9ad59..6764dad 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -90,6 +90,12 @@ version = "1.0.93" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c95c10ba0b00a02636238b814946408b1322d5ac4760326e6fb8ec956d85775" +[[package]] +name = "arraydeque" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d902e3d592a523def97af8f317b08ce16b7ab854c1985a0c671e6f15cebc236" + [[package]] name = "autocfg" version = "1.3.0" @@ -498,6 +504,12 @@ dependencies = [ "serde", ] +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + [[package]] name = "bytes" version = "1.6.0" @@ -676,6 +688,12 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "foldhash" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f81ec6369c545a7d40e4589b5597581fa1c441fe1cce96dd1de43159910a36a2" + [[package]] name = "form_urlencoded" version = "1.2.1" @@ -812,6 +830,26 @@ dependencies = [ "allocator-api2", ] +[[package]] +name = "hashbrown" +version = "0.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a9bfc1af68b1726ea47d3d5109de126281def866b33970e10fbab11b5dafab3" +dependencies = [ + "allocator-api2", + "equivalent", + "foldhash", +] + +[[package]] +name = "hashlink" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8094feaf31ff591f651a2664fb9cfd92bba7a60ce3197265e9482ebe753c8f7" +dependencies = [ + "hashbrown 0.14.5", +] + [[package]] name = "heck" version = "0.5.0" @@ -964,7 +1002,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" dependencies = [ "equivalent", - "hashbrown", + "hashbrown 0.14.5", ] [[package]] @@ -991,12 +1029,6 @@ version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" -[[package]] -name = "libyaml-safer" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2cff24caa08828851c9b7ed1bce365b1d2496b9323dd0d4b241c1d10135f5bd6" - [[package]] name = "lock_api" version = "0.4.12" @@ -1272,9 +1304,9 @@ dependencies = [ [[package]] name = "rsjsonnet-front" -version = "0.1.1" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b532a8af07b6781c59a68b7e55745720e26a043ae780c67f5789bf90eaad1c5c" +checksum = "4c49c7a2d195ba780dd95738ea920ad413636b68572b33167357b608a64da317" dependencies = [ "rsjsonnet-lang", "sourceannot", @@ -1282,13 +1314,15 @@ dependencies = [ [[package]] name = "rsjsonnet-lang" -version = "0.1.1" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1776c10b94e43de20c39493d947acc339098eb97d2369795238584f76defda66" +checksum = "e4e1e32cd07aac2d7a0ad2a72982bd133b772d7c8b78e47c448d29aa7c5cac52" dependencies = [ - "hashbrown", - "libyaml-safer", + "bumpalo", + "foldhash", + "hashbrown 0.15.1", "md-5", + "saphyr-parser", ] [[package]] @@ -1355,6 +1389,16 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" +[[package]] +name = "saphyr-parser" +version = "0.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "123f0a6da68f3072c7c761450276d1d444cb391c8be182a757cd26cf684cb77f" +dependencies = [ + "arraydeque", + "hashlink", +] + [[package]] name = "schannel" version = "0.1.23" @@ -1517,9 +1561,9 @@ dependencies = [ [[package]] name = "sourceannot" -version = "0.2.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "806ab42b7a19d82b5f611462f3de3234a1032e16f1837209fc874d7041401d91" +checksum = "d1266b6cd460a74a33feaca00abc1c85617b20e9790f0effff696deeee75578d" dependencies = [ "unicode-width", ] diff --git a/Cargo.toml b/Cargo.toml index 7cc0c21..1b09204 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/jsonnet_evaluator.rs b/src/jsonnet_evaluator.rs index 9c2c5b9..158c440 100644 --- a/src/jsonnet_evaluator.rs +++ b/src/jsonnet_evaluator.rs @@ -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 { 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());