refactor(command_parser): simplify how tokens are defined in commands

This commit is contained in:
dusk 2025-01-24 04:08:59 +09:00
parent f804e7629f
commit 071db3d6d6
No known key found for this signature in database
9 changed files with 114 additions and 76 deletions

View file

@ -90,27 +90,7 @@ impl Display for Command {
// (and something like &dyn Trait would require everything to be referenced which doesnt look nice anyway)
#[macro_export]
macro_rules! command {
([$($v:expr),+] => $cb:expr$(,)*) => {
($($v:expr),+ => $cb:expr$(,)*) => {
$crate::command::Command::new($crate::tokens!($($v),+), $cb)
};
($tokens:expr => $cb:expr$(,)*) => {
$crate::command::Command::new($tokens.clone(), $cb)
};
($tokens:expr, $($v:expr),+ => $cb:expr$(,)*) => {
$crate::command::Command::new($crate::concat_tokens!($tokens.clone(), [$($v),+]), $cb)
};
}
#[macro_export]
macro_rules! tokens {
($($v:expr),+$(,)*) => {
[$($crate::token::Token::from($v)),+]
};
}
#[macro_export]
macro_rules! concat_tokens {
($tokens:expr, [$($v:expr),+]$(,)*) => {
$tokens.clone().into_iter().chain($crate::tokens!($($v),+).into_iter()).collect::<Vec<_>>()
};
}