Created
June 16, 2014 21:08
-
-
Save reem/08b7ca26fb1e1aec3abb 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
#![feature(phase, macro_rules)] | |
extern crate regex; | |
#[phase(plugin)] extern crate regex_macros; | |
macro_rules! matching( | |
($($a:tt),+) => ( | |
regex!(concat!("^", glob_to_regex!($($a))+, "$")) | |
); | |
) | |
macro_rules! glob_to_regex( | |
(Segment($a:ident), $r:tt*) => ( | |
concat!("/", stringify!($a), "/", glob_to_regex!($r)), | |
); | |
(Binding($a:ident), $r:tt*) => ( | |
concat!("/([a-zA-Z0-9_-]*)/", glob_to_regex!($r)), | |
); | |
(DoubleStar, $r:tt*) => ( | |
concat!("/[/a-zA-Z0-9_-]*", glob_to_regex($r)) | |
); | |
(Star, $r:tt*) => ( | |
concat!("/[a-zA-Z0-9_-]*/", glob_to_regex($r)), | |
); | |
) | |
fn main() { | |
let reg = matching!(Segment(users), Star); | |
println!("{}", reg.is_match("/users/hello")); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment