Skip to content

Commit

Permalink
fix: support 42-at-most branches for nom::branch::alt
Browse files Browse the repository at this point in the history
NonAnyType has 29 arms, more than builtin-supported 21 ones

Refer: rust-bakery/nom#1144
  • Loading branch information
flisky committed Aug 4, 2022
1 parent e9ec184 commit 9b0dbd8
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions weedle2/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ macro_rules! weedle {
};
}

macro_rules! alt {
($member0:expr, $($member1:expr, $member2:expr,)*) => {
alt!(@as_expr $member0, $(nom::branch::alt(($member1, $member2)),)+)
};
($($member0:expr, $member1:expr,)*) => {
alt!(@as_expr $(nom::branch::alt(($member0, $member1)),)+)
};
(@as_expr $($member:expr,)*) => {
nom::branch::alt(($($member,)+))
};
}

macro_rules! ast_types {
(@extract_type struct $name:ident<'a> $($rest:tt)*) => ($name<'a>);
(@extract_type struct $name:ident $($rest:tt)*) => ($name);
Expand Down Expand Up @@ -430,9 +442,9 @@ macro_rules! __ast_enum {
{ }
) => (
impl<'a> $crate::Parse<'a> for $name<$($maybe_a)*> {
parser!(nom::branch::alt((
parser!(alt!(
$(nom::combinator::map(weedle!($member), From::from),)*
)));
));
}
);
(@build_parse
Expand Down

0 comments on commit 9b0dbd8

Please sign in to comment.