Macro sexpr_script

Source
sexpr_script!() { /* proc-macro */ }
Expand description

Parse a string of s-expressions into an array of kamo::value::Values.

The syntax is defined by the Scheme standard R7RS for the read procedure. For the deviations from the standard see the documentation of the macros crate.

The macro takes an optional MutatorRef identifier. This is used to allocate values on the heap. If the expression does not contain any values that need to be allocated on the heap, then the Mutator identifier can be omitted.

The syntax is sexpr_script!(<mutator>, <expressions>).

§Examples

use kamo::{mem::Mutator, sexpr_script, value::{print, Value}};
  
let m = Mutator::new_ref();
let values: &[Value] = &sexpr_script!(m, "(define a 1)\n(define b 2)\n(+ a b)");
  
assert_eq!(values.len(), 3);
assert_eq!(print(values[0].clone()).to_string(), "(define a 1)");
assert_eq!(print(values[1].clone()).to_string(), "(define b 2)");
assert_eq!(print(values[2].clone()).to_string(), "(+ a b)");

let values: &[Value] = &sexpr_script!("");
  
assert_eq!(values.len(), 0);