Last active
August 29, 2015 14:01
-
-
Save bstrie/f30a968b83af7d01716d 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(macro_rules)] | |
macro_rules! iota( | |
($($thing:expr),+) => (iota_expr!(1, $($thing),*)); | |
($($thing:pat),+) => (iota_pat!(1, $($thing),*)); | |
() => (()); | |
) | |
macro_rules! iota_expr( | |
($id:expr, $head:expr, $($tail:expr),*) => ({ | |
println!("expr {}", $id); iota_expr!($id+1, $($tail),*); | |
}); | |
($id:expr, $last:expr) => ({ println!("expr {}", $id); }); | |
) | |
macro_rules! iota_pat( | |
($id:expr, $head:pat, $($tail:pat),*) => ({ | |
println!("pat {}", $id); iota_pat!($id+1, $($tail),*); | |
}); | |
($id:expr, $last:pat) => ({ println!("pat {}", $id); }); | |
) | |
fn test_iota() { | |
println!("empty test"); | |
iota!(); | |
// expr | |
println!("expr test"); | |
iota!(9); | |
iota!(9,9,9); | |
// ident - matched by expr | |
println!("ident test"); | |
iota!(Nine); | |
iota!(Nine,Nine,Nine); | |
// ty - matched by expr | |
println!("ty test"); | |
iota!(Option::<int>); | |
iota!(Option::<int>,Option::<int>,Option::<int>); | |
// block - matched by expr | |
println!("block test"); | |
iota!({9;9}); | |
iota!({9;9},{9;9},{9;9}); | |
// pat | |
println!("pat test"); | |
iota!(foo @ _); | |
iota!(foo @ _,foo @ _,foo @ _); | |
} | |
fn main() { | |
test_iota(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment