Macro rust_lisp::lisp

source ·
macro_rules! lisp {
    ( { $e:expr } ) => { ... };
    ( ( $($val:tt)* ) ) => { ... };
    (nil) => { ... };
    (NIL) => { ... };
    (t) => { ... };
    (T) => { ... };
    (f) => { ... };
    (F) => { ... };
    ($sym:ident) => { ... };
    ( + ) => { ... };
    ( - ) => { ... };
    ( * ) => { ... };
    ( / ) => { ... };
    ( == ) => { ... };
    ( != ) => { ... };
    ( < ) => { ... };
    ( <= ) => { ... };
    ( > ) => { ... };
    ( >= ) => { ... };
    ($e:literal) => { ... };
}
Expand description

A macro for more easily creating s-expressions from within Rust code

fn parse_basic_expression() {
    let ast1 = parse(
        "
       (+ 3 1)",
    )
    .next()
    .unwrap()
    .unwrap();

    let n = 2;
    let ast2 = lisp! {
        (+ { Value::Int(n + 1) } 1)
    };

    assert_eq!(
        ast1,
        ast2
    );
}