#[macro_export]
macro_rules! tt_replace {
{
$caller:tt
condition = [{ $($condition:ident)::* }]
replace_with = [{ $($with:tt)* }]
input = [{ $($input:tt)* }]
} => {
$crate::private_replace! {
$caller
condition = [{ $($condition)::* }]
replace_with = [{ $($with)* }]
tokens = [{ }]
rest = [{ $($input)* }]
}
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! private_replace {
{
$caller:tt
condition = [{ $($condition:ident)::* }]
replace_with = [{ $($with:tt)* }]
tokens = [{ $($tokens:tt)* }]
rest = [{ }]
} => {
$crate::tt_return! {
$caller
tokens = [{ $($tokens)* }]
}
};
{
$caller:tt
condition = [{ $($condition:ident)::* }]
replace_with = [{ $($with:tt)* }]
tokens = [{ $($tokens:tt)* }]
rest = [{ ( $($group:tt)* ) $($rest:tt)* }]
} => {
$crate::tt_call! {
macro = [{ $crate::private_replace }]
condition = [{ $($condition)::* }]
replace_with = [{ $($with)* }]
tokens = [{ }]
rest = [{ $($group)* }]
~~> $crate::private_replace! {
$caller
condition = [{ $($condition)::* }]
replace_with = [{ $($with)* }]
tokens = [{ $($tokens)* }]
after_paren = [{ $($rest)* }]
}
}
};
{
$caller:tt
condition = [{ $($condition:ident)::* }]
replace_with = [{ $($with:tt)* }]
tokens = [{ $($tokens:tt)* }]
after_paren = [{ $($after:tt)* }]
tokens = [{ $($inside:tt)* }]
} => {
$crate::private_replace! {
$caller
condition = [{ $($condition)::* }]
replace_with = [{ $($with)* }]
tokens = [{ $($tokens)* ( $($inside)* ) }]
rest = [{ $($after)* }]
}
};
{
$caller:tt
condition = [{ $($condition:ident)::* }]
replace_with = [{ $($with:tt)* }]
tokens = [{ $($tokens:tt)* }]
rest = [{ [ $($group:tt)* ] $($rest:tt)* }]
} => {
$crate::tt_call! {
macro = [{ $crate::private_replace }]
condition = [{ $($condition)::* }]
replace_with = [{ $($with)* }]
tokens = [{ }]
rest = [{ $($group)* }]
~~> $crate::private_replace! {
$caller
condition = [{ $($condition)::* }]
replace_with = [{ $($with)* }]
tokens = [{ $($tokens)* }]
after_bracket = [{ $($rest)* }]
}
}
};
{
$caller:tt
condition = [{ $($condition:ident)::* }]
replace_with = [{ $($with:tt)* }]
tokens = [{ $($tokens:tt)* }]
after_bracket = [{ $($after:tt)* }]
tokens = [{ $($inside:tt)* }]
} => {
$crate::private_replace! {
$caller
condition = [{ $($condition)::* }]
replace_with = [{ $($with)* }]
tokens = [{ $($tokens)* [ $($inside)* ] }]
rest = [{ $($after)* }]
}
};
{
$caller:tt
condition = [{ $($condition:ident)::* }]
replace_with = [{ $($with:tt)* }]
tokens = [{ $($tokens:tt)* }]
rest = [{ { $($group:tt)* } $($rest:tt)* }]
} => {
$crate::tt_call! {
macro = [{ $crate::private_replace }]
condition = [{ $($condition)::* }]
replace_with = [{ $($with)* }]
tokens = [{ }]
rest = [{ $($group)* }]
~~> $crate::private_replace! {
$caller
condition = [{ $($condition)::* }]
replace_with = [{ $($with)* }]
tokens = [{ $($tokens)* }]
after_brace = [{ $($rest)* }]
}
}
};
{
$caller:tt
condition = [{ $($condition:ident)::* }]
replace_with = [{ $($with:tt)* }]
tokens = [{ $($tokens:tt)* }]
after_brace = [{ $($after:tt)* }]
tokens = [{ $($inside:tt)* }]
} => {
$crate::private_replace! {
$caller
condition = [{ $($condition)::* }]
replace_with = [{ $($with)* }]
tokens = [{ $($tokens)* { $($inside)* } }]
rest = [{ $($after)* }]
}
};
{
$caller:tt
condition = [{ $($condition:ident)::* }]
replace_with = [{ $($with:tt)* }]
tokens = [{ $($tokens:tt)* }]
rest = [{ $first:tt $($rest:tt)* }]
} => {
$crate::tt_if! {
condition = [{ $($condition)::* }]
input = [{ $first }]
true = [{
$crate::private_replace! {
$caller
condition = [{ $($condition)::* }]
replace_with = [{ $($with)* }]
tokens = [{ $($tokens)* $($with)* }]
rest = [{ $($rest)* }]
}
}]
false = [{
$crate::private_replace! {
$caller
condition = [{ $($condition)::* }]
replace_with = [{ $($with)* }]
tokens = [{ $($tokens)* $first }]
rest = [{ $($rest)* }]
}
}]
}
};
}