Rust Quasi-Quoting macro with pretty template-engine like syntax
This crate provides quasi-quoting macros like quote.
This crate has backward-compatibility with original quote! macro and also provides
new template-engine like syntax.
This crate is get some inspiration from proc-quote.
Using this crate
This crate is useful for developing proc-macro. Usually an proc-macro crate using template_quote is placed with following Cargo.toml:
[]
= "your_crate_name"
= "0.0.0"
= "2021"
[]
= true
[]
= "0.1"
= "1.0"
and with following src/lib.rs code:
extern crate proc_macro;
extern crate proc_macro2;
extern crate template_quote;
use quote;
use TokenStream;
use TokenStream as TokenStream2;
then you will be able to use it like:
extern crate your_crate_name;
use my_macro;
my_macro!
Original syntax
Original quote! macro syntax is fully supported. See quote's doc.
Template-engine like syntax
Conditional blocks
template_quote supports if, else, else if, for .. in .., while .., while let ..., loop syntax like following:
let tokens = quote! ;
assert_eq!;
You can also set an separater for for, while, loop, placing a separater between #(..) and {..}.
Inline statements / expressions
You can use inline expression by syntax #{ ... }.
let v = vec!;
let tokens = quote! ;
assert_eq!;
Limitation
- Let binding in
#{ ... }within traditional repetition syntax#( .. )*does not work. - If the punct token before '#' in the macro body has
Spacing::Join, then the emitting punct also has same spacing, whether the '#' token is processed by the macro or not.