Rust
Latest commit 15889ec Jan 27, 2017 @dtolnay dtolnay Release 0.32.0

README.md

Rust Quasi-Quoting Syntax Extension

Build Status Latest Version

Quasi is a quasi-quotation macro library that allows you produce Rust AST from Rust syntax. Furthermore, it allows you to easily splice local variables into the quoted string in order to have it inserted into the produced AST.

Example

Here is a simple example to build the syntax::ast::Expr that represents adding two numbers together:

#![feature(plugin, rustc_private)]
#![plugin(quasi_macros)]

extern crate syntax;
extern crate quasi;

use syntax::ext::base::ExtCtxt;

fn make_ext_ctxt(...) -> ExtCtxt {
    ...
}

fn main() {
    let cx = make_ext_ctxt(...);
    let y = 2;
    let expr = quote_expr!(cx, 1 + $y);

    // prints `1 + 2`.
    println!("{}", syntax::pprint::expr_to_string(&expr));
}