Skip to content
/ ama Public

Anonymous procedural macro in Rust

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

ptal/ama

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Anonymous procedural macro in Rust

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages