Skip to content

Commit

Permalink
Change the order of macro parsing (#4)
Browse files Browse the repository at this point in the history
When using macros `or_continue`, `or_continue_quiet`, `or_break` and
`or_break_quiet` with loop labels, we need to change the macro parsing
order
  • Loading branch information
rick68 authored Nov 5, 2024
1 parent a356907 commit a1e96eb
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,22 +256,22 @@ macro_rules! or_return_quiet {
/// Accepts an optional 'label as the first argument.
#[macro_export]
macro_rules! or_continue {
($expr:expr $(,)?) => {
($label:tt, $expr:expr $(,)?) => {
match $crate::IntoResult::into_result($expr) {
Ok(x) => x,
Err(e) => {
$crate::__log_on_bail!($expr, e);
continue;
continue $label;
}
}
};

($label:lifetime, $expr:expr $(,)?) => {
($expr:expr $(,)?) => {
match $crate::IntoResult::into_result($expr) {
Ok(x) => x,
Err(e) => {
$crate::__log_on_bail!($expr, e);
continue $label;
continue;
}
}
};
Expand All @@ -282,17 +282,17 @@ macro_rules! or_continue {
/// Accepts an optional 'label as the first argument.
#[macro_export]
macro_rules! or_continue_quiet {
($expr:expr $(,)?) => {
($label:tt, $expr:expr $(,)?) => {
match $crate::IntoResult::into_result($expr) {
Ok(x) => x,
_ => continue,
_ => continue $label,
}
};

($label:lifetime, $expr:expr $(,)?) => {
($expr:expr $(,)?) => {
match $crate::IntoResult::into_result($expr) {
Ok(x) => x,
_ => continue $label,
_ => continue,
}
};
}
Expand All @@ -302,22 +302,22 @@ macro_rules! or_continue_quiet {
/// Accepts an optional 'label as the first argument.
#[macro_export]
macro_rules! or_break {
($expr:expr $(,)?) => {
($label:tt, $expr:expr $(,)?) => {
match $crate::IntoResult::into_result($expr) {
Ok(x) => x,
Err(e) => {
$crate::__log_on_bail!($expr, e);
break;
break $label;
}
}
};

($label:lifetime, $expr:expr $(,)?) => {
($expr:expr $(,)?) => {
match $crate::IntoResult::into_result($expr) {
Ok(x) => x,
Err(e) => {
$crate::__log_on_bail!($expr, e);
break $label;
break;
}
}
};
Expand All @@ -328,17 +328,17 @@ macro_rules! or_break {
/// Accepts an optional 'label as the first argument.
#[macro_export]
macro_rules! or_break_quiet {
($expr:expr $(,)?) => {
($label:tt, $expr:expr $(,)?) => {
match $crate::IntoResult::into_result($expr) {
Ok(x) => x,
_ => break,
_ => break $label,
}
};

($label:lifetime, $expr:expr $(,)?) => {
($expr:expr $(,)?) => {
match $crate::IntoResult::into_result($expr) {
Ok(x) => x,
_ => break $label,
_ => break,
}
};
}
Expand Down

0 comments on commit a1e96eb

Please # to comment.