Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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