#edsl #proc-macro #macro #syntax #quasiquote

nightly ama

Quasi-quotation system for designing procedural macros mixed with Rust code

2 releases

Uses old Rust 2015

0.1.4 Aug 19, 2016
0.1.3 Aug 15, 2016

#1557 in Procedural macros

MIT/Apache

16KB
325 lines

Anonymous Procedural Macro

ptal on Travis CI

Compiled on the nightly channel of Rust. Use rustup for managing compiler channels. Download the exact same version of the compiler used with rustup override add nightly-2016-08-12.

This library is used for anonymously escaping code inside Rust code and avoiding repeating my_language!(code) everywhere. This is a tool for people implementing procedural macros and trying to integrate their language into Rust. It uses an escape mechanism (the # symbol) to specify we enter the user-language world.

Example with the pcp EDSL (truncated and modified for clarity):

pcp! {
  // ...
  for _ in 0..n {
    let n: i32 = n as i32;
    queens.push(#(variables <- 0..n));
  }
  for i in 0..n-1 {
    for j in i + 1..n {
      let a = i as i32;
      let b = j as i32;
      #{
        constraints <- queens[i] + a != queens[j] + b;
        constraints <- queens[i] - a != queens[j] - b;
      }
    }
  }
  // ...
}

Traditional Rust code is in the macro pcp! but we easily escape our user-defined language with #(code) or #{code} depending on the nature of the generated code (expression or statements). Control will be given to the user-compiler (parameter of the main function compile_anonymous_macro) for the code inside # and the generated Rust code will be automatically inserted.

License

Licensed under either of

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you shall be dual licensed as above, without any additional terms or conditions.

No runtime deps