#jsonnet #error #source #library #loading #printing #front-end

rsjsonnet-front

A Jsonnet front end (source loading and error printing) library

2 releases

new 0.1.1 Apr 21, 2024
0.1.0 Apr 6, 2024

#9 in #jsonnet

Download history 172/week @ 2024-04-04 58/week @ 2024-04-11 205/week @ 2024-04-18

435 downloads per month
Used in rsjsonnet

MIT/Apache

625KB
15K SLoC

rsjsonnet-front

crates.io Documentation MSRV License

A Rust library that sits in the middle between rsjsonnet-lang and the outer world. Provides source loading and error printing.


lib.rs:

A library that provides a frontend (loading source files and printing errors) for Jsonnet interpreters.

Example

let source = b"local add_one(x) = x + 1; add_one(2)";

// Create a session, which will contain a `rsjsonnet_lang::program::Program`.
let mut session = rsjsonnet_front::Session::new();

// Load a virtual (i.e., not from the file system) source file into the program
let Some(thunk) = session.load_virt_file("<example>", source.to_vec()) else {
    // `Session` printed the error for us
    return;
};

// Evaluate it
let Some(value) = session.eval_value(&thunk) else {
    // `Session` printed the error for us
    return;
};

assert_eq!(value.as_number(), Some(3.0));

// Manifest the value
let Some(json_result) = session.manifest_json(&value, false) else {
    // `Session` printed the error for us
    return;
};

assert_eq!(json_result, "3");

Dependencies

~2–8MB
~46K SLoC