rsjsonnet_front/lib.rs
1#![warn(
2 rust_2018_idioms,
3 trivial_casts,
4 trivial_numeric_casts,
5 unreachable_pub,
6 unused_qualifications
7)]
8#![forbid(unsafe_code)]
9
10//! A library that provides a frontend (loading source files and printing
11//! errors) for Jsonnet interpreters.
12//!
13//! # Example
14//!
15//! ```
16//! let source = b"local add_one(x) = x + 1; add_one(2)";
17//!
18//! // Create the arena allocator.
19//! let arena = rsjsonnet_lang::arena::Arena::new();
20//!
21//! // Create a session, which will contain a `rsjsonnet_lang::program::Program`.
22//! let mut session = rsjsonnet_front::Session::new(&arena);
23//!
24//! // Load a virtual (i.e., not from the file system) source file into the program
25//! let Some(thunk) = session.load_virt_file("<example>", source.to_vec()) else {
26//! // `Session` printed the error for us
27//! return;
28//! };
29//!
30//! // Evaluate it
31//! let Some(value) = session.eval_value(&thunk) else {
32//! // `Session` printed the error for us
33//! return;
34//! };
35//!
36//! assert_eq!(value.as_number(), Some(3.0));
37//!
38//! // Manifest the value
39//! let Some(json_result) = session.manifest_json(&value, false) else {
40//! // `Session` printed the error for us
41//! return;
42//! };
43//!
44//! assert_eq!(json_result, "3");
45//! ```
46
47mod print;
48mod report;
49mod session;
50mod src_manager;
51
52pub use session::Session;