Skip to content

Commit

Permalink
Reduce indentation in generated macro output
Browse files Browse the repository at this point in the history
Useful when debugging with cargo-expand
  • Loading branch information
madsmtm committed Oct 27, 2022
1 parent 14449d7 commit de5ed69
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 28 deletions.
48 changes: 30 additions & 18 deletions objc2/src/macros/extern_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,17 +449,17 @@ macro_rules! __attribute_helper {
$($rest:tt)*
)
$($macro_args:tt)*
} => {{
} => {
$crate::__attribute_helper! {
@extract_sel_duplicate
$($rest)*
($($rest)*)
$out_macro!(
$($macro_args)*
// Append selector to the end of the macro arguments
@($($sel)*)
)
}

$out_macro!(
$($macro_args)*
@($($sel)*)
)
}};
};
{
@extract_sel
($out_macro:path)
Expand All @@ -468,14 +468,14 @@ macro_rules! __attribute_helper {
$($rest:tt)*
)
$($macro_args:tt)*
} => {{
} => {
$crate::__attribute_helper! {
@extract_sel
($out_macro)
($($rest)*)
$($macro_args)*
}
}};
};
{
@extract_sel
($out_macro:path)
Expand All @@ -487,21 +487,33 @@ macro_rules! __attribute_helper {

{
@extract_sel_duplicate
#[sel($($_sel_args:tt)*)]
$($rest:tt)*
(
#[sel($($_sel_args:tt)*)]
$($rest:tt)*
)
$($output:tt)*
} => {{
compile_error!("Cannot not specify a selector twice!");
}};
{
@extract_sel_duplicate
#[$($m_checked:tt)*]
$($rest:tt)*
} => {{
(
#[$($m_checked:tt)*]
$($rest:tt)*
)
$($output:tt)*
} => {
$crate::__attribute_helper! {
@extract_sel_duplicate
$($rest)*
($($rest:tt)*)
$($output)*
}
};
{
@extract_sel_duplicate
()
$($output:tt)*
} => {{
$($output)*
}};
{@extract_sel_duplicate} => {};

}
19 changes: 9 additions & 10 deletions objc2/src/macros/extern_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,12 +319,12 @@ macro_rules! __inner_extern_methods {
@($($args_rest:tt)*)
@($($sel:tt)*)
} => {
$crate::__collect_msg_send!(
$crate::__collect_msg_send! {
$crate::msg_send;
$self;
($($sel)*);
($($args_rest)*);
)
}
};
{
@unsafe_method_body
Expand All @@ -336,12 +336,12 @@ macro_rules! __inner_extern_methods {
@($($args_rest:tt)*)
@($($sel:tt)*)
} => {
$crate::__collect_msg_send!(
$crate::__collect_msg_send! {
$crate::msg_send;
Self::class();
($($sel)*);
($($args_rest)*);
)
}
};
}

Expand Down Expand Up @@ -377,16 +377,15 @@ macro_rules! __collect_msg_send {
($sel:ident : $($sel_rest:tt)*);
($arg:ident: $arg_ty:ty $(, $($args_rest:tt)*)?);
$($output:tt)*
) => {{
$crate::__collect_msg_send!(
) => {
$crate::__collect_msg_send! {
$macro;
$obj;
($($sel_rest)*);
($($($args_rest)*)?);
$($output)*
$sel: $arg,
)
}};
$($output)* $sel: $arg,
}
};

// If couldn't zip selector and arguments, show useful error message
($($_any:tt)*) => {{
Expand Down

0 comments on commit de5ed69

Please sign in to comment.