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

rsjsonnet-front

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

5 unstable releases

0.3.0 Nov 7, 2024
0.2.0 Aug 12, 2024
0.1.2 Jul 20, 2024
0.1.1 Apr 21, 2024
0.1.0 Apr 6, 2024

#1302 in Web programming

Download history 130/week @ 2024-07-27 152/week @ 2024-08-10 50/week @ 2024-08-17 59/week @ 2024-08-24 30/week @ 2024-08-31 165/week @ 2024-09-07 54/week @ 2024-09-14 14/week @ 2024-09-21 35/week @ 2024-09-28 2/week @ 2024-10-05 94/week @ 2024-10-12 31/week @ 2024-10-19 126/week @ 2024-11-02 68/week @ 2024-11-09

260 downloads per month
Used in rsjsonnet

MIT/Apache

730KB
18K 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 the arena allocator.
let arena = rsjsonnet_lang::arena::Arena::new();

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

// 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

~4–12MB
~145K SLoC