Created
February 3, 2025 01:07
-
-
Save balthild/38e631502446ce9cdad2653eeb0ca5c6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[macro_export] | |
macro_rules! lazy_regex { | |
{ $($e:expr)* } => {{ | |
use ::std::sync::LazyLock; | |
use ::regex_lite::Regex; | |
static __RE: LazyLock<Regex> = LazyLock::new(|| { | |
Regex::new(concat!($($e),*)).unwrap() | |
}); | |
&*__RE | |
}}; | |
} | |
#[macro_export] | |
macro_rules! regex { | |
{ $($e:expr)* } => { | |
concat!($($e),*) | |
}; | |
} | |
#[macro_export] | |
macro_rules! re_capture { | |
{ [$name:ident] $($e:expr)* } => { | |
concat!(r"(?<", stringify!($name), ">", $($e),*, r")") | |
}; | |
} | |
#[macro_export] | |
macro_rules! re_optional { | |
{ $($e:expr)* } => { | |
concat!(r"(?:", $($e),*, r")?") | |
}; | |
} | |
#[macro_export] | |
macro_rules! re_repeat { | |
{ [+] $($e:expr)* } => { | |
concat!(r"(?:", $($e),*, r")+") | |
}; | |
{ [*] $($e:expr)* } => { | |
concat!(r"(?:", $($e),*, r")*") | |
}; | |
{ [$count:expr] $($e:expr)* } => { | |
concat!(r"(?:", $($e),*, r"){", $count, "}") | |
}; | |
} | |
#[macro_export] | |
macro_rules! re_seplist { | |
{ [$sep:expr] $($e:expr)* } => { | |
concat!($($e),*, "(?:", $sep, $($e),*, ")*") | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment