[][src]Macro glsp::backquote

backquote!() { /* proc-macro */ }

Equivalent to `.

The input must be a string literal which parses into a single value. The macro emits Rust code which will construct that value and return it. For example, backquote!("(a 1)") could potentially expand to:

arr![glsp::sym("a"), 1]

Auto-gensyms, e.g. name#, are supported.

The result has a generic return type - it can be any type which implements FromVal. It should be bound to a local variable with a concrete type.

let arr: Root<Arr> = backquote!("(a b c)");
let i: i64 = backquote!("100");
let val: Val = backquote!("#((key0 #t) (key1 #f))");

If the input contains any unquoted forms (typically using the ~ abbreviation), each unquoted form must be a symbol which names a local variable in the same scope as the backquote!() invocation. That local variable must implement the IntoVal trait. It's converted into a Val which is interpolated into the output.

Local variables can be borrowed by typing ~&var_name. This prevents the variable from being consumed by the backquote!() invocation. If T is the variable's type, its shared reference &T must implement the IntoVal trait.

Local variables can be simultaneously unquoted and splayed with ~... In that case, the borrowed form of the local variable must belong to a type which implements Splay.

If any of the IntoVal conversions fail, the generated code will panic. For a non-panicking version of this macro, use try_backquote!().

let c = 100_u64;
let d = [200_u16, 250];
let e = vec![275.0_f32, 287.5];
let val: Val = backquote!(r#"
  (a "b" ~c ~..d ~&e)
"#);
println!("{}", val); //prints (a "b" 100 200 250 275.0 287.5)

This macro can be more convenient than using arr![] to construct complicated nested forms. It's particularly useful when implementing GameLisp macros in Rust.