#[doc(hidden)]
#[macro_export]
macro_rules! text_impl {
([$style_id:ident : $lit:literal $($rest:tt)*] $($done:tt)*) => {
$crate::text_impl!([$($rest)*] $($done)*, $crate::Segment {
style: Some($crate::Style::$style_id), text: $lit, ticks: true
})
};
([$style_id:ident : {$ex:expr} $($rest:tt)*] $($done:tt)*) => {
$crate::text_impl!([$($rest)*] $($done)*, $crate::Segment {
style: Some($crate::Style::$style_id), text: $ex, ticks: true
})
};
([$style_id:ident ! $lit:literal $($rest:tt)*] $($done:tt)*) => {
$crate::text_impl!([$($rest)*] $($done)*, $crate::Segment {
style: Some($crate::Style::$style_id), text: $lit, ticks: false
})
};
([$style_id:ident ! {$ex:expr} $($rest:tt)*] $($done:tt)*) => {
$crate::text_impl!([$($rest)*] $($done)*, $crate::Segment {
style: Some($crate::Style::$style_id), text: $ex, ticks: false
})
};
([$lit:literal $($rest:tt)*] $($done:tt)*) => {
$crate::text_impl!([$($rest)*] $($done)*, $crate::Segment::new($lit))
};
([{$ex:expr} $($rest:tt)*] $($done:tt)*) => {
$crate::text_impl!([$($rest)*] $($done)*, $crate::Segment::new($ex))
};
([], $($done:tt)*) => {
&[$($done)*]
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! rhs_impl {
({ $($inner:tt)* }) => {
$crate::sections!( $($inner)* )
};
($e:expr) => {
$e
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! sections_impl {
(@[ [$($text:tt)*] $($rest:tt)* ] $($done:tt)*) => {
$crate::sections_impl!(
@[ $($rest)* ] $($done)*,
$crate::HelpSection::Text($crate::text![ $($text)* ])
)
};
(@[ table $mode:ident { $( $key:literal => $rhs:tt )* } $($rest:tt)* ] $($done:tt)*) => {
$crate::sections_impl!(
@[ $($rest)* ] $($done)*,
$crate::HelpSection::Table($crate::TableMode::$mode, &[$(
( $key, $crate::rhs_impl!($rhs) ),
)*])
)
};
(@[ $name:literal $rhs:tt $($rest:tt)* ] $($done:tt)*) => {
$crate::sections_impl!(
@[ $($rest)* ] $($done)*,
$crate::HelpSection::Name($name, $crate::rhs_impl!($rhs))
)
};
(@[ $wrapper:ident [$($text:tt)* ] $($rest:tt)* ] $($done:tt)*) => {
$crate::sections_impl!(
@[ $($rest)* ] $($done)*,
$crate::HelpSection::$wrapper(
&$crate::HelpSection::Text($crate::text![ $($text)* ])
)
)
};
(@[ $wrapper:ident table $mode:ident { $( $key:literal => $rhs:tt )* } $($rest:tt)* ] $($done:tt)*) => {
$crate::sections_impl!(
@[ $($rest)* ] $($done)*,
$crate::HelpSection::$wrapper(
&$crate::HelpSection::Table($crate::TableMode::$mode, &[$(
( $key, $crate::rhs_impl!($rhs) ),
)*])
)
)
};
(@[ $wrapper:ident $name:literal $rhs:tt $($rest:tt)* ] $($done:tt)*) => {
$crate::sections_impl!(
@[$($rest)*] $($done)*,
$crate::HelpSection::$wrapper(
&$crate::HelpSection::Name($name, $crate::rhs_impl!($rhs))
)
)
};
(@[ { $($inner:tt)* } $($rest:tt)* ] $($done:tt)*) => {
$crate::sections_impl!(
@[$($rest)*] $($done)*,
$($inner)*
)
};
(@[], $($done:tt)*) => {
&[ $($done)* ]
};
}
#[macro_export]
macro_rules! text {
() => {
&[]
};
($($rest:tt)*) => {
$crate::text_impl!([ $($rest)* ])
};
}
#[macro_export]
macro_rules! sections {
() => {
&[]
};
($($rest:tt)*) => {
$crate::sections_impl!(@[ $($rest)* ])
};
}