with_builtin_macros-proc_macros 0.0.3

Helper for macro_rules authors to chain their macros with builtin ones (such as `env!`, `include!`, or `concat_idents!`).
Documentation
use super::*;

pub(in crate)
struct CompileTimeString /* = */ (
    pub(in crate) String,
);

impl Parse for CompileTimeString {
    fn parse (input: ParseStream<'_>)
      -> Result<Self>
    {
        let lookahead = input.lookahead1();
        macro_rules! compile_time_string_macros {(
            $(
                $macro_name:ident !(...)
            ),+ $(,)?
        ) => ({
            mod kw {
                $(
                    ::syn::custom_keyword!($macro_name);
                )+
            }
            match () {
                _case if lookahead.peek(LitStr) => {
                    Ok(Self(
                        input
                            .parse::<LitStr>()
                            .unwrap()
                            .value()
                    ))
                },
                $(
                    _case if lookahead.peek(kw::$macro_name) => {
                        let _: kw::$macro_name = input.parse().unwrap();
                        let _: Token![!] = input.parse()?;
                        let contents = input.parse::<Group>()?.stream();
                        Ok(Self(
                            crate::builtin::$macro_name::call_on(contents)?
                        ))
                    },
                )+
                _default => Err(lookahead.error()),
            }
        })}
        return compile_time_string_macros![
            concat!(...),
            env!(...),
            include_str_from_root!(...),
            stringify!(...),
        ];
    }
}