Crates.io | ama |
lib.rs | ama |
version | 0.1.4 |
source | src |
created_at | 2016-08-15 15:32:16.291011 |
updated_at | 2016-08-19 08:47:21.716421 |
description | Quasi-quotation system for designing procedural macros mixed with Rust code. |
homepage | |
repository | https://github.com/ptal/ama |
max_upload_size | |
id | 5979 |
size | 28,801 |
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.
Licensed under either of
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.