difftreelog
feat CLI
in: master
6 files changed
Cargo.lockdiffbeforeafterboth10 packageslockfile v1
Might be heavy and slow!
closure
0.3.0crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumd6173fd61b610d15a7566dd7b7620775627441c4ab9dac8906e17cb93a24b782used byjsonnet-evaluator
0.1.0workspace↘ 3↖ 0jsonnet-parser
0.1.0workspace↘ 2↖ 1depends onused byjsonnet-stdlib
0.1.0workspace↘ 0↖ 2peg
0.6.2crates.io↘ 2↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum9075875c14bb21f25f11cad4b6ad2e4dd443b8fb83900b2fbdd6ebd744b82e97depends onused bypeg-macros
0.6.2crates.io↘ 3↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumc24c165fd39e995246140cc78df55c56c6733ba87e6658cb3e197b8856c62852used bypeg-runtime
0.6.2crates.io↘ 0↖ 2sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum0c1a2897e69d986c7986747ebad425cf03746ec5e3e09bb3b2600f91301ba864used byproc-macro2
1.0.12crates.io↘ 1↖ 2sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum8872cf6f48eee44265156c111456a700ab3483686b3f96df4cf5481c89157319depends onused byquote
1.0.5crates.io↘ 1↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum42934bc9c8ab0d3b273a16d8551c8f0fcff46be73276ca083ec2414c15c4ba5edepends onused byunicode-xid
0.2.0crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097cused by
43 packageslockfile v1
Might be heavy and slow!
annotate-snippets
0.8.0crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumd78ea013094e5ea606b1c05fe35f1dd7ea1eb1ea259908d040b25bd5ec677ee5used byatty
0.2.14crates.io↘ 3↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumd9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8depends onused byautocfg
1.0.0crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumf8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9dused bybitflags
1.2.1crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumcf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693used byclap
3.0.0-beta.1crates.io↘ 12↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum860643c53f980f0d38a5e25dfab6c3c93b2cb3aa1fe192643d17a293c6c41936depends onused byclap_derive
3.0.0-beta.1crates.io↘ 5↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumfb51c9e75b94452505acd21d929323f5a5c6c4735a852adbd39ef5fb1b014f30used byclosure
0.3.0crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumd6173fd61b610d15a7566dd7b7620775627441c4ab9dac8906e17cb93a24b782used byheck
0.3.1crates.io↘ 1↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205depends onused byhermit-abi
0.1.13crates.io↘ 1↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum91780f809e750b0a89f5544be56617ff6b1227ee485bcb06ebe10cdf89bd3b71depends onused byindexmap
1.4.0crates.io↘ 1↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumc398b2b113b55809ceb9ee3e753fcbac793f1956663f3c36549c1346015c2afedepends onused byjsonnet
0.1.0workspace↘ 3↖ 0jsonnet-evaluator
0.1.0workspace↘ 3↖ 1used byjsonnet-parser
0.1.0workspace↘ 2↖ 1depends onused byjsonnet-stdlib
0.1.0workspace↘ 0↖ 2kernel32-sys
0.2.2crates.io↘ 2↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098ddepends onused bylazy_static
1.4.0crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksume2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646used bylibc
0.2.71crates.io↘ 0↖ 4sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum9457b06509d27052635f90d6466700c65095fdf75409b3fbdd903e988b886f49os_str_bytes
2.3.1crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum06de47b848347d8c4c94219ad8ecd35eb90231704b067e67e6ae2e36ee023510used bypeg
0.6.2crates.io↘ 2↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum9075875c14bb21f25f11cad4b6ad2e4dd443b8fb83900b2fbdd6ebd744b82e97depends onused bypeg-macros
0.6.2crates.io↘ 3↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumc24c165fd39e995246140cc78df55c56c6733ba87e6658cb3e197b8856c62852used bypeg-runtime
0.6.2crates.io↘ 0↖ 2sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum0c1a2897e69d986c7986747ebad425cf03746ec5e3e09bb3b2600f91301ba864used byproc-macro-error
0.4.12crates.io↘ 5↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum18f33027081eba0a6d8aba6d1b1c3a3be58cbb12106341c2d5759fcd9b5277e7used byproc-macro-error-attr
0.4.12crates.io↘ 5↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum8a5b4b77fdb63c1eca72173d68d24501c54ab1269409f6b672c85deb18af69deused byproc-macro2
1.0.12crates.io↘ 1↖ 7sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum8872cf6f48eee44265156c111456a700ab3483686b3f96df4cf5481c89157319depends onquote
1.0.5crates.io↘ 1↖ 6sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum42934bc9c8ab0d3b273a16d8551c8f0fcff46be73276ca083ec2414c15c4ba5edepends onstrsim
0.10.0crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623used bysyn
1.0.21crates.io↘ 3↖ 4sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum4696caa4048ac7ce2bcd2e484b3cef88c1004e41b8e945a277e2c25dc0b72060syn-mid
0.5.0crates.io↘ 3↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum7be3539f6c128a931cf19dcee741c1af532c7fd387baa739c03dd2e96479338adepends onused byterm_size
0.3.2crates.io↘ 2↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum1e4129646ca0ed8f45d09b929036bafad5377103edd06e50bf574b353d2b08d9depends onused byterm_size
1.0.0-beta1crates.io↘ 3↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksuma8a17d8699e154863becdf18e4fd28bd0be27ca72856f54daf75c00f2566898fdepends onused bytermcolor
1.1.0crates.io↘ 1↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumbb6bfa289a4d7c5766392812c0a1f4c1ba45afa1ad47803c11e1f407d846d75fdepends onused bytextwrap
0.11.0crates.io↘ 2↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumd326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060depends onused byunicode-segmentation
1.6.0crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksume83e153d1053cbb5a118eeff7fd5be06ed99153f00dbcd8ae310c5fb2b22edc0used byunicode-width
0.1.7crates.io↘ 0↖ 2sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumcaaa9d531767d1ff2150b9332433f32a24622147e5ebb1f26409d5da67afd479unicode-xid
0.2.0crates.io↘ 0↖ 2sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097cused byvec_map
0.8.2crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumf1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191used byversion_check
0.9.2crates.io↘ 0↖ 2sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumb5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aedwinapi
0.2.8crates.io↘ 0↖ 2sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087awinapi
0.3.8crates.io↘ 2↖ 3sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6winapi-build
0.1.1crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bcused bywinapi-i686-pc-windows-gnu
0.4.0crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6used bywinapi-util
0.1.5crates.io↘ 1↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178depends onused bywinapi-x86_64-pc-windows-gnu
0.4.0crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183fused by
Cargo.tomldiffbeforeafterboth--- a/Cargo.toml
+++ b/Cargo.toml
@@ -3,4 +3,5 @@
"crates/jsonnet-parser",
"crates/jsonnet-evaluator",
"crates/jsonnet-stdlib",
+ "cmds/jsonnet"
]
cmds/jsonnet/Cargo.tomldiffbeforeafterboth--- /dev/null
+++ b/cmds/jsonnet/Cargo.toml
@@ -0,0 +1,16 @@
+[package]
+name = "jsonnet"
+version = "0.1.0"
+authors = ["Лач <iam@lach.pw>"]
+edition = "2018"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
+jsonnet-evaluator = { path = "../../crates/jsonnet-evaluator" }
+annotate-snippets = "0.8.0"
+
+[dependencies.clap]
+version = "3.0.0-beta.1"
+default-features = false
+features = ["std", "derive", "suggestions", "color", "unstable", "wrap_help"]
cmds/jsonnet/src/main.rsdiffbeforeafterboth--- /dev/null
+++ b/cmds/jsonnet/src/main.rs
@@ -0,0 +1,64 @@
+use clap::Clap;
+
+#[derive(Clap)]
+#[clap(version = "0.1.0", author = "Lach <iam@lach.pw>")]
+struct Opts {
+ #[clap(about = "File to compile")]
+ input: String,
+ #[clap(long, about = "Disable global std variable")]
+ no_stdlib: bool,
+}
+
+fn main() {
+ let opts: Opts = Opts::parse();
+ let evaluator = jsonnet_evaluator::EvaluationState::default();
+ if !opts.no_stdlib {
+ evaluator.add_stdlib();
+ }
+ evaluator
+ .add_file(
+ opts.input.clone(),
+ String::from_utf8(std::fs::read(opts.input.clone()).unwrap()).unwrap(),
+ )
+ .unwrap();
+ let result = evaluator.evaluate_file(&opts.input.clone());
+ match result {
+ Ok(v) => println!("{:?}", v),
+ Err(err) => {
+ use annotate_snippets::{
+ display_list::{DisplayList, FormatOptions},
+ snippet::{Annotation, AnnotationType, Slice, Snippet, SourceAnnotation},
+ };
+ for item in (err.1).0.iter() {
+ let source = (item.0).1.clone().unwrap();
+ let code = evaluator.get_source(&source.0);
+ let snippet = Snippet {
+ opt: FormatOptions {
+ color: true,
+ ..Default::default()
+ },
+ title: Some(Annotation {
+ label: Some(&item.1),
+ id: None,
+ annotation_type: AnnotationType::Error,
+ }),
+ footer: vec![],
+ slices: vec![Slice {
+ source: &code,
+ line_start: 1,
+ origin: Some(&source.0),
+ fold: true,
+ annotations: vec![SourceAnnotation {
+ label: &"Example error annotation",
+ annotation_type: AnnotationType::Error,
+ range: (source.1, source.2),
+ }],
+ }],
+ };
+
+ let dl = DisplayList::from(snippet);
+ println!("{}", dl);
+ }
+ }
+ }
+}
crates/jsonnet-evaluator/src/evaluate.rsdiffbeforeafterboth--- a/crates/jsonnet-evaluator/src/evaluate.rs
+++ b/crates/jsonnet-evaluator/src/evaluate.rs
@@ -77,6 +77,7 @@
(Val::Str(v1), Val::Str(v2)) => Val::Str(v1.to_owned() + &v2),
(Val::Str(v1), Val::Num(v2)) => Val::Str(format!("{}{}", v1, v2)),
(Val::Num(v1), Val::Str(v2)) => Val::Str(format!("{}{}", v1, v2)),
+ (Val::Str(v1), v2) => Val::Str(format!("{}{:?}", v1, v2)),
(Val::Obj(v1), Val::Obj(v2)) => Val::Obj(v2.with_super(v1.clone())),
(Val::Arr(a), Val::Arr(b)) => Val::Arr([&a[..], &b[..]].concat()),
(Val::Num(v1), Val::Num(v2)) => Val::Num(v1 + v2),
crates/jsonnet-evaluator/src/lib.rsdiffbeforeafterboth--- a/crates/jsonnet-evaluator/src/lib.rs
+++ b/crates/jsonnet-evaluator/src/lib.rs
@@ -84,6 +84,13 @@
Ok(())
}
+ pub fn get_source(&self, name: &str) -> String {
+ let ro_map = self.0.files.borrow();
+ let value = ro_map
+ .get(name)
+ .unwrap_or_else(|| panic!("file not added: {:?}", name));
+ value.0.clone()
+ }
pub fn evaluate_file(&self, name: &str) -> Result<Val> {
self.begin_state();
let expr: LocExpr = {