mirror of
https://github.com/uutils/coreutils
synced 2024-11-17 02:08:09 +00:00
build/uucore_procs ~ add/improve debug infrastructure
- add proc_dbg! macro - use debug feature to trigger debug traits for the syn crate
This commit is contained in:
parent
cf2fcd8dc1
commit
a352657e1f
2 changed files with 27 additions and 7 deletions
|
@ -11,8 +11,9 @@ proc-macro = true
|
|||
[dependencies]
|
||||
proc-macro2 = "1.0"
|
||||
quote = "1.0"
|
||||
syn = { version="1.0" } ## debug: use `features=["extra-traits"]` to add Debug traits to structs (for `println!("{:?}", ...)`)
|
||||
syn = { version="1.0" }
|
||||
|
||||
[features]
|
||||
default = []
|
||||
debug = []
|
||||
## non-default features
|
||||
debug = ["syn/extra-traits"] ## add Debug traits to syn structs (for `println!("{:?}", ...)`)
|
||||
|
|
|
@ -6,6 +6,30 @@ extern crate proc_macro;
|
|||
//* ref: <https://dev.to/naufraghi/procedural-macro-in-rust-101-k3f> @@ <http://archive.is/Vbr5e>
|
||||
//* ref: [path construction from LitStr](https://oschwald.github.io/maxminddb-rust/syn/struct.LitStr.html) @@ <http://archive.is/8YDua>
|
||||
|
||||
//## proc_dbg macro
|
||||
//* used to help debug the compile-time proc_macro code
|
||||
|
||||
#[cfg(feature = "debug")]
|
||||
macro_rules! proc_dbg {
|
||||
($x:expr) => {
|
||||
dbg!($x)
|
||||
};
|
||||
}
|
||||
#[cfg(not(feature = "debug"))]
|
||||
macro_rules! proc_dbg {
|
||||
($x:expr) => {
|
||||
std::convert::identity($x)
|
||||
};
|
||||
}
|
||||
|
||||
//## main!()
|
||||
|
||||
// main!( EXPR )
|
||||
// generates a `main()` function for utilities within the uutils group
|
||||
// EXPR == syn::Expr::Lit::String | syn::Expr::Path::Ident ~ EXPR contains the location of the utility `uumain()` function
|
||||
//* for future use of "eager" macros and more generic use, EXPR may be in either STRING or IDENT form
|
||||
//* for ease-of-use, the trailing "::uumain" is optional and will be added if needed
|
||||
|
||||
struct Tokens {
|
||||
expr: syn::Expr,
|
||||
}
|
||||
|
@ -18,11 +42,6 @@ impl syn::parse::Parse for Tokens {
|
|||
}
|
||||
}
|
||||
|
||||
// main!( EXPR )
|
||||
// generates a `main()` function for utilities within the uutils group
|
||||
// EXPR == syn::Expr::Lit::String | syn::Expr::Path::Ident ~ EXPR contains the location of the utility `uumain()` function
|
||||
//* for future use of "eager" macros and more generic use, EXPR may be in either STRING or IDENT form
|
||||
//* for ease-of-use, the trailing "::uumain" is optional and will be added if needed
|
||||
#[proc_macro]
|
||||
pub fn main(stream: proc_macro::TokenStream) -> proc_macro::TokenStream {
|
||||
let Tokens { expr } = syn::parse_macro_input!(stream as Tokens);
|
||||
|
|
Loading…
Reference in a new issue