diff --git a/src/uucore/src/uucore_procs/Cargo.toml b/src/uucore/src/uucore_procs/Cargo.toml index 0e1f9eb6f..62c60394e 100644 --- a/src/uucore/src/uucore_procs/Cargo.toml +++ b/src/uucore/src/uucore_procs/Cargo.toml @@ -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!("{:?}", ...)`) diff --git a/src/uucore/src/uucore_procs/src/lib.rs b/src/uucore/src/uucore_procs/src/lib.rs index 9b49314f6..f1409f19f 100644 --- a/src/uucore/src/uucore_procs/src/lib.rs +++ b/src/uucore/src/uucore_procs/src/lib.rs @@ -6,6 +6,30 @@ extern crate proc_macro; //* ref: @@ //* ref: [path construction from LitStr](https://oschwald.github.io/maxminddb-rust/syn/struct.LitStr.html) @@ +//## 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);