Created
December 25, 2018 14:32
-
-
Save dherman/fac5fe937646117bdf41febffc7c8243 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_rules! const1 { | |
($id:ident, $depth:expr, [$($prefix:tt)*]) | |
=> | |
{ | |
const $id: [&'static str; $depth] = [$($prefix),*]; | |
}; | |
} | |
macro_rules! const_tree_at { | |
($depth:tt ; | |
[$($prefix:tt)*] ; | |
;) | |
=> | |
{ }; | |
($depth:tt ; | |
[$($prefix:tt)*] ; | |
{ }) | |
=> | |
{ }; | |
($depth:tt ; | |
[$($prefix:tt)*] ; | |
{ $name:tt => $id:ident $subtree:tt $($more:tt)* }) | |
=> | |
{ | |
const1!($id, ($depth + 1), [$($prefix)* $name]); | |
const_tree_at!(($depth + 1) ; [ $($prefix)* $name ] ; $subtree); | |
const_tree_at!($depth ; [$($prefix)*] ; { $($more)* }); | |
}; | |
} | |
macro_rules! const_tree { | |
($($t:tt)*) => { | |
const_tree_at!(0 ; [] ; { $($t)* }); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment