simplify const_regex macro

The :vis macro matcher has been stable for a long time now.
Let's use it, and replace the recursion with a plus pattern.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2021-05-04 14:50:56 +02:00 committed by Dietmar Maurer
parent 9c786006df
commit e3a78d6354

View File

@ -39,21 +39,11 @@ impl std::ops::Deref for ConstRegexPattern {
/// ``` /// ```
#[macro_export] #[macro_export]
macro_rules! const_regex { macro_rules! const_regex {
() => {}; ($(
($(#[$attr:meta])* pub ($($vis:tt)+) $name:ident = $regex:expr; $($rest:tt)*) => { $(#[$attr:meta])*
$crate::const_regex! { (pub ($($vis)+)) $(#[$attr])* $name = $regex; $($rest)* } $vis:vis $name:ident = $regex:expr;
}; )+) => { $(
($(#[$attr:meta])* pub $name:ident = $regex:expr; $($rest:tt)*) => { $(#[$attr])* $vis const $name: $crate::api::const_regex::ConstRegexPattern =
$crate::const_regex! { (pub) $(#[$attr])* $name = $regex; $($rest)* }
};
($(#[$attr:meta])* $name:ident = $regex:expr; $($rest:tt)*) => {
$crate::const_regex! { () $(#[$attr])* $name = $regex; $($rest)* }
};
(
($($pub:tt)*) $(#[$attr:meta])* $name:ident = $regex:expr;
$($rest:tt)*
) => {
$(#[$attr])* $($pub)* const $name: $crate::api::const_regex::ConstRegexPattern =
$crate::api::const_regex::ConstRegexPattern { $crate::api::const_regex::ConstRegexPattern {
regex_string: $regex, regex_string: $regex,
regex_obj: (|| -> &'static ::regex::Regex { regex_obj: (|| -> &'static ::regex::Regex {
@ -63,9 +53,7 @@ macro_rules! const_regex {
&SCHEMA &SCHEMA
}) })
}; };
)+ };
$crate::const_regex! { $($rest)* }
};
} }
#[cfg(feature = "test-harness")] #[cfg(feature = "test-harness")]