Coverage Report

Created: 2024-09-08 06:35

/rust/registry/src/index.crates.io-6f17d22bba15001f/nom-7.1.1/src/branch/mod.rs
Line
Count
Source (jump to first uncovered line)
1
//! Choice combinators
2
3
macro_rules! succ (
4
  (0, $submac:ident ! ($($rest:tt)*)) => ($submac!(1, $($rest)*));
5
  (1, $submac:ident ! ($($rest:tt)*)) => ($submac!(2, $($rest)*));
6
  (2, $submac:ident ! ($($rest:tt)*)) => ($submac!(3, $($rest)*));
7
  (3, $submac:ident ! ($($rest:tt)*)) => ($submac!(4, $($rest)*));
8
  (4, $submac:ident ! ($($rest:tt)*)) => ($submac!(5, $($rest)*));
9
  (5, $submac:ident ! ($($rest:tt)*)) => ($submac!(6, $($rest)*));
10
  (6, $submac:ident ! ($($rest:tt)*)) => ($submac!(7, $($rest)*));
11
  (7, $submac:ident ! ($($rest:tt)*)) => ($submac!(8, $($rest)*));
12
  (8, $submac:ident ! ($($rest:tt)*)) => ($submac!(9, $($rest)*));
13
  (9, $submac:ident ! ($($rest:tt)*)) => ($submac!(10, $($rest)*));
14
  (10, $submac:ident ! ($($rest:tt)*)) => ($submac!(11, $($rest)*));
15
  (11, $submac:ident ! ($($rest:tt)*)) => ($submac!(12, $($rest)*));
16
  (12, $submac:ident ! ($($rest:tt)*)) => ($submac!(13, $($rest)*));
17
  (13, $submac:ident ! ($($rest:tt)*)) => ($submac!(14, $($rest)*));
18
  (14, $submac:ident ! ($($rest:tt)*)) => ($submac!(15, $($rest)*));
19
  (15, $submac:ident ! ($($rest:tt)*)) => ($submac!(16, $($rest)*));
20
  (16, $submac:ident ! ($($rest:tt)*)) => ($submac!(17, $($rest)*));
21
  (17, $submac:ident ! ($($rest:tt)*)) => ($submac!(18, $($rest)*));
22
  (18, $submac:ident ! ($($rest:tt)*)) => ($submac!(19, $($rest)*));
23
  (19, $submac:ident ! ($($rest:tt)*)) => ($submac!(20, $($rest)*));
24
  (20, $submac:ident ! ($($rest:tt)*)) => ($submac!(21, $($rest)*));
25
);
26
27
#[cfg(test)]
28
mod tests;
29
30
use crate::error::ErrorKind;
31
use crate::error::ParseError;
32
use crate::internal::{Err, IResult, Parser};
33
34
/// Helper trait for the [alt()] combinator.
35
///
36
/// This trait is implemented for tuples of up to 21 elements
37
pub trait Alt<I, O, E> {
38
  /// Tests each parser in the tuple and returns the result of the first one that succeeds
39
  fn choice(&mut self, input: I) -> IResult<I, O, E>;
40
}
41
42
/// Tests a list of parsers one by one until one succeeds.
43
///
44
/// It takes as argument a tuple of parsers. There is a maximum of 21
45
/// parsers. If you need more, it is possible to nest them in other `alt` calls,
46
/// like this: `alt(parser_a, alt(parser_b, parser_c))`
47
///
48
/// ```rust
49
/// # use nom::error_position;
50
/// # use nom::{Err,error::ErrorKind, Needed, IResult};
51
/// use nom::character::complete::{alpha1, digit1};
52
/// use nom::branch::alt;
53
/// # fn main() {
54
/// fn parser(input: &str) -> IResult<&str, &str> {
55
///   alt((alpha1, digit1))(input)
56
/// };
57
///
58
/// // the first parser, alpha1, recognizes the input
59
/// assert_eq!(parser("abc"), Ok(("", "abc")));
60
///
61
/// // the first parser returns an error, so alt tries the second one
62
/// assert_eq!(parser("123456"), Ok(("", "123456")));
63
///
64
/// // both parsers failed, and with the default error type, alt will return the last error
65
/// assert_eq!(parser(" "), Err(Err::Error(error_position!(" ", ErrorKind::Digit))));
66
/// # }
67
/// ```
68
///
69
/// With a custom error type, it is possible to have alt return the error of the parser
70
/// that went the farthest in the input data
71
0
pub fn alt<I: Clone, O, E: ParseError<I>, List: Alt<I, O, E>>(
72
0
  mut l: List,
73
0
) -> impl FnMut(I) -> IResult<I, O, E> {
74
0
  move |i: I| l.choice(i)
Unexecuted instantiation: nom::branch::alt::<&str, &str, nom::error::Error<&str>, (nom::combinator::value<&str, &str, char, nom::error::Error<&str>, nom::character::complete::char<&str, nom::error::Error<&str>>::{closure#0}>::{closure#0}, nom::combinator::value<&str, &str, char, nom::error::Error<&str>, nom::character::complete::char<&str, nom::error::Error<&str>>::{closure#0}>::{closure#0})>::{closure#0}
Unexecuted instantiation: nom::branch::alt::<&str, &str, nom::error::Error<&str>, (nom::bytes::complete::is_not<&str, &str, nom::error::Error<&str>>::{closure#0}, nom::bytes::complete::tag<&str, &str, nom::error::Error<&str>>::{closure#0})>::{closure#0}
Unexecuted instantiation: nom::branch::alt::<&str, alloc::borrow::Cow<str>, nom::error::Error<&str>, (nom::combinator::map<&str, alloc::string::String, alloc::borrow::Cow<str>, nom::error::Error<&str>, nom::bytes::complete::escaped_transform<&str, nom::error::Error<&str>, nom::character::complete::none_of<&str, &str, nom::error::Error<&str>>::{closure#0}, nom::branch::alt<&str, &str, nom::error::Error<&str>, (nom::combinator::value<&str, &str, char, nom::error::Error<&str>, nom::character::complete::char<&str, nom::error::Error<&str>>::{closure#0}>::{closure#0}, nom::combinator::value<&str, &str, char, nom::error::Error<&str>, nom::character::complete::char<&str, nom::error::Error<&str>>::{closure#0}>::{closure#0})>::{closure#0}, char, &str, char, alloc::string::String>::{closure#0}, alloc::borrow::Cow<str>::Owned>::{closure#0}, nom::combinator::map<&str, &str, alloc::borrow::Cow<str>, nom::error::Error<&str>, nom::bytes::complete::tag<&str, &str, nom::error::Error<&str>>::{closure#0}, alloc::borrow::Cow<str>::Borrowed>::{closure#0})>::{closure#0}
Unexecuted instantiation: nom::branch::alt::<&str, alloc::borrow::Cow<str>, nom::error::Error<&str>, (nom::sequence::delimited<&str, char, alloc::borrow::Cow<str>, char, nom::error::Error<&str>, nom::character::complete::char<&str, nom::error::Error<&str>>::{closure#0}, nom::branch::alt<&str, alloc::borrow::Cow<str>, nom::error::Error<&str>, (nom::combinator::map<&str, alloc::string::String, alloc::borrow::Cow<str>, nom::error::Error<&str>, nom::bytes::complete::escaped_transform<&str, nom::error::Error<&str>, nom::character::complete::none_of<&str, &str, nom::error::Error<&str>>::{closure#0}, nom::branch::alt<&str, &str, nom::error::Error<&str>, (nom::combinator::value<&str, &str, char, nom::error::Error<&str>, nom::character::complete::char<&str, nom::error::Error<&str>>::{closure#0}>::{closure#0}, nom::combinator::value<&str, &str, char, nom::error::Error<&str>, nom::character::complete::char<&str, nom::error::Error<&str>>::{closure#0}>::{closure#0})>::{closure#0}, char, &str, char, alloc::string::String>::{closure#0}, alloc::borrow::Cow<str>::Owned>::{closure#0}, nom::combinator::map<&str, &str, alloc::borrow::Cow<str>, nom::error::Error<&str>, nom::bytes::complete::tag<&str, &str, nom::error::Error<&str>>::{closure#0}, alloc::borrow::Cow<str>::Borrowed>::{closure#0})>::{closure#0}, nom::character::complete::char<&str, nom::error::Error<&str>>::{closure#0}>::{closure#0}, nom::combinator::map<&str, &str, alloc::borrow::Cow<str>, nom::error::Error<&str>, nom::sequence::delimited<&str, char, &str, char, nom::error::Error<&str>, nom::character::complete::char<&str, nom::error::Error<&str>>::{closure#0}, nom::branch::alt<&str, &str, nom::error::Error<&str>, (nom::bytes::complete::is_not<&str, &str, nom::error::Error<&str>>::{closure#0}, nom::bytes::complete::tag<&str, &str, nom::error::Error<&str>>::{closure#0})>::{closure#0}, nom::character::complete::char<&str, nom::error::Error<&str>>::{closure#0}>::{closure#0}, alloc::borrow::Cow<str>::Borrowed>::{closure#0}, nom::combinator::map<&str, &str, alloc::borrow::Cow<str>, nom::error::Error<&str>, nom::bytes::complete::take_while1<serde_keyvalue::key_values::any_string::{closure#0}, &str, nom::error::Error<&str>>::{closure#0}, alloc::borrow::Cow<str>::Borrowed>::{closure#0})>::{closure#0}
Unexecuted instantiation: nom::branch::alt::<&str, bool, nom::error::Error<&str>, (nom::combinator::value<&str, bool, &str, nom::error::Error<&str>, nom::bytes::complete::tag<&str, &str, nom::error::Error<&str>>::{closure#0}>::{closure#0}, nom::combinator::value<&str, bool, &str, nom::error::Error<&str>, nom::bytes::complete::tag<&str, &str, nom::error::Error<&str>>::{closure#0}>::{closure#0})>::{closure#0}
Unexecuted instantiation: nom::branch::alt::<&str, u32, nom::error::Error<&str>, (nom::combinator::value<&str, u32, &str, nom::error::Error<&str>, nom::bytes::complete::tag<&str, &str, nom::error::Error<&str>>::{closure#0}>::{closure#0}, nom::combinator::value<&str, u32, &str, nom::error::Error<&str>, nom::bytes::complete::tag<&str, &str, nom::error::Error<&str>>::{closure#0}>::{closure#0}, nom::combinator::value<&str, u32, &str, nom::error::Error<&str>, nom::bytes::complete::tag<&str, &str, nom::error::Error<&str>>::{closure#0}>::{closure#0})>::{closure#0}
Unexecuted instantiation: nom::branch::alt::<_, _, _, _>::{closure#0}
75
0
}
Unexecuted instantiation: nom::branch::alt::<&str, &str, nom::error::Error<&str>, (nom::combinator::value<&str, &str, char, nom::error::Error<&str>, nom::character::complete::char<&str, nom::error::Error<&str>>::{closure#0}>::{closure#0}, nom::combinator::value<&str, &str, char, nom::error::Error<&str>, nom::character::complete::char<&str, nom::error::Error<&str>>::{closure#0}>::{closure#0})>
Unexecuted instantiation: nom::branch::alt::<&str, &str, nom::error::Error<&str>, (nom::bytes::complete::is_not<&str, &str, nom::error::Error<&str>>::{closure#0}, nom::bytes::complete::tag<&str, &str, nom::error::Error<&str>>::{closure#0})>
Unexecuted instantiation: nom::branch::alt::<&str, alloc::borrow::Cow<str>, nom::error::Error<&str>, (nom::combinator::map<&str, alloc::string::String, alloc::borrow::Cow<str>, nom::error::Error<&str>, nom::bytes::complete::escaped_transform<&str, nom::error::Error<&str>, nom::character::complete::none_of<&str, &str, nom::error::Error<&str>>::{closure#0}, nom::branch::alt<&str, &str, nom::error::Error<&str>, (nom::combinator::value<&str, &str, char, nom::error::Error<&str>, nom::character::complete::char<&str, nom::error::Error<&str>>::{closure#0}>::{closure#0}, nom::combinator::value<&str, &str, char, nom::error::Error<&str>, nom::character::complete::char<&str, nom::error::Error<&str>>::{closure#0}>::{closure#0})>::{closure#0}, char, &str, char, alloc::string::String>::{closure#0}, alloc::borrow::Cow<str>::Owned>::{closure#0}, nom::combinator::map<&str, &str, alloc::borrow::Cow<str>, nom::error::Error<&str>, nom::bytes::complete::tag<&str, &str, nom::error::Error<&str>>::{closure#0}, alloc::borrow::Cow<str>::Borrowed>::{closure#0})>
Unexecuted instantiation: nom::branch::alt::<&str, alloc::borrow::Cow<str>, nom::error::Error<&str>, (nom::sequence::delimited<&str, char, alloc::borrow::Cow<str>, char, nom::error::Error<&str>, nom::character::complete::char<&str, nom::error::Error<&str>>::{closure#0}, nom::branch::alt<&str, alloc::borrow::Cow<str>, nom::error::Error<&str>, (nom::combinator::map<&str, alloc::string::String, alloc::borrow::Cow<str>, nom::error::Error<&str>, nom::bytes::complete::escaped_transform<&str, nom::error::Error<&str>, nom::character::complete::none_of<&str, &str, nom::error::Error<&str>>::{closure#0}, nom::branch::alt<&str, &str, nom::error::Error<&str>, (nom::combinator::value<&str, &str, char, nom::error::Error<&str>, nom::character::complete::char<&str, nom::error::Error<&str>>::{closure#0}>::{closure#0}, nom::combinator::value<&str, &str, char, nom::error::Error<&str>, nom::character::complete::char<&str, nom::error::Error<&str>>::{closure#0}>::{closure#0})>::{closure#0}, char, &str, char, alloc::string::String>::{closure#0}, alloc::borrow::Cow<str>::Owned>::{closure#0}, nom::combinator::map<&str, &str, alloc::borrow::Cow<str>, nom::error::Error<&str>, nom::bytes::complete::tag<&str, &str, nom::error::Error<&str>>::{closure#0}, alloc::borrow::Cow<str>::Borrowed>::{closure#0})>::{closure#0}, nom::character::complete::char<&str, nom::error::Error<&str>>::{closure#0}>::{closure#0}, nom::combinator::map<&str, &str, alloc::borrow::Cow<str>, nom::error::Error<&str>, nom::sequence::delimited<&str, char, &str, char, nom::error::Error<&str>, nom::character::complete::char<&str, nom::error::Error<&str>>::{closure#0}, nom::branch::alt<&str, &str, nom::error::Error<&str>, (nom::bytes::complete::is_not<&str, &str, nom::error::Error<&str>>::{closure#0}, nom::bytes::complete::tag<&str, &str, nom::error::Error<&str>>::{closure#0})>::{closure#0}, nom::character::complete::char<&str, nom::error::Error<&str>>::{closure#0}>::{closure#0}, alloc::borrow::Cow<str>::Borrowed>::{closure#0}, nom::combinator::map<&str, &str, alloc::borrow::Cow<str>, nom::error::Error<&str>, nom::bytes::complete::take_while1<serde_keyvalue::key_values::any_string::{closure#0}, &str, nom::error::Error<&str>>::{closure#0}, alloc::borrow::Cow<str>::Borrowed>::{closure#0})>
Unexecuted instantiation: nom::branch::alt::<&str, bool, nom::error::Error<&str>, (nom::combinator::value<&str, bool, &str, nom::error::Error<&str>, nom::bytes::complete::tag<&str, &str, nom::error::Error<&str>>::{closure#0}>::{closure#0}, nom::combinator::value<&str, bool, &str, nom::error::Error<&str>, nom::bytes::complete::tag<&str, &str, nom::error::Error<&str>>::{closure#0}>::{closure#0})>
Unexecuted instantiation: nom::branch::alt::<&str, u32, nom::error::Error<&str>, (nom::combinator::value<&str, u32, &str, nom::error::Error<&str>, nom::bytes::complete::tag<&str, &str, nom::error::Error<&str>>::{closure#0}>::{closure#0}, nom::combinator::value<&str, u32, &str, nom::error::Error<&str>, nom::bytes::complete::tag<&str, &str, nom::error::Error<&str>>::{closure#0}>::{closure#0}, nom::combinator::value<&str, u32, &str, nom::error::Error<&str>, nom::bytes::complete::tag<&str, &str, nom::error::Error<&str>>::{closure#0}>::{closure#0})>
Unexecuted instantiation: nom::branch::alt::<_, _, _, _>
76
77
/// Helper trait for the [permutation()] combinator.
78
///
79
/// This trait is implemented for tuples of up to 21 elements
80
pub trait Permutation<I, O, E> {
81
  /// Tries to apply all parsers in the tuple in various orders until all of them succeed
82
  fn permutation(&mut self, input: I) -> IResult<I, O, E>;
83
}
84
85
/// Applies a list of parsers in any order.
86
///
87
/// Permutation will succeed if all of the child parsers succeeded.
88
/// It takes as argument a tuple of parsers, and returns a
89
/// tuple of the parser results.
90
///
91
/// ```rust
92
/// # use nom::{Err,error::{Error, ErrorKind}, Needed, IResult};
93
/// use nom::character::complete::{alpha1, digit1};
94
/// use nom::branch::permutation;
95
/// # fn main() {
96
/// fn parser(input: &str) -> IResult<&str, (&str, &str)> {
97
///   permutation((alpha1, digit1))(input)
98
/// }
99
///
100
/// // permutation recognizes alphabetic characters then digit
101
/// assert_eq!(parser("abc123"), Ok(("", ("abc", "123"))));
102
///
103
/// // but also in inverse order
104
/// assert_eq!(parser("123abc"), Ok(("", ("abc", "123"))));
105
///
106
/// // it will fail if one of the parsers failed
107
/// assert_eq!(parser("abc;"), Err(Err::Error(Error::new(";", ErrorKind::Digit))));
108
/// # }
109
/// ```
110
///
111
/// The parsers are applied greedily: if there are multiple unapplied parsers
112
/// that could parse the next slice of input, the first one is used.
113
/// ```rust
114
/// # use nom::{Err, error::{Error, ErrorKind}, IResult};
115
/// use nom::branch::permutation;
116
/// use nom::character::complete::{anychar, char};
117
///
118
/// fn parser(input: &str) -> IResult<&str, (char, char)> {
119
///   permutation((anychar, char('a')))(input)
120
/// }
121
///
122
/// // anychar parses 'b', then char('a') parses 'a'
123
/// assert_eq!(parser("ba"), Ok(("", ('b', 'a'))));
124
///
125
/// // anychar parses 'a', then char('a') fails on 'b',
126
/// // even though char('a') followed by anychar would succeed
127
/// assert_eq!(parser("ab"), Err(Err::Error(Error::new("b", ErrorKind::Char))));
128
/// ```
129
///
130
0
pub fn permutation<I: Clone, O, E: ParseError<I>, List: Permutation<I, O, E>>(
131
0
  mut l: List,
132
0
) -> impl FnMut(I) -> IResult<I, O, E> {
133
0
  move |i: I| l.permutation(i)
134
0
}
135
136
macro_rules! alt_trait(
137
  ($first:ident $second:ident $($id: ident)+) => (
138
    alt_trait!(__impl $first $second; $($id)+);
139
  );
140
  (__impl $($current:ident)*; $head:ident $($id: ident)+) => (
141
    alt_trait_impl!($($current)*);
142
143
    alt_trait!(__impl $($current)* $head; $($id)+);
144
  );
145
  (__impl $($current:ident)*; $head:ident) => (
146
    alt_trait_impl!($($current)*);
147
    alt_trait_impl!($($current)* $head);
148
  );
149
);
150
151
macro_rules! alt_trait_impl(
152
  ($($id:ident)+) => (
153
    impl<
154
      Input: Clone, Output, Error: ParseError<Input>,
155
      $($id: Parser<Input, Output, Error>),+
156
    > Alt<Input, Output, Error> for ( $($id),+ ) {
157
158
0
      fn choice(&mut self, input: Input) -> IResult<Input, Output, Error> {
159
0
        match self.0.parse(input.clone()) {
160
0
          Err(Err::Error(e)) => alt_trait_inner!(1, self, input, e, $($id)+),
161
0
          res => res,
162
        }
163
0
      }
Unexecuted instantiation: <(nom::sequence::delimited<&str, char, alloc::borrow::Cow<str>, char, nom::error::Error<&str>, nom::character::complete::char<&str, nom::error::Error<&str>>::{closure#0}, nom::branch::alt<&str, alloc::borrow::Cow<str>, nom::error::Error<&str>, (nom::combinator::map<&str, alloc::string::String, alloc::borrow::Cow<str>, nom::error::Error<&str>, nom::bytes::complete::escaped_transform<&str, nom::error::Error<&str>, nom::character::complete::none_of<&str, &str, nom::error::Error<&str>>::{closure#0}, nom::branch::alt<&str, &str, nom::error::Error<&str>, (nom::combinator::value<&str, &str, char, nom::error::Error<&str>, nom::character::complete::char<&str, nom::error::Error<&str>>::{closure#0}>::{closure#0}, nom::combinator::value<&str, &str, char, nom::error::Error<&str>, nom::character::complete::char<&str, nom::error::Error<&str>>::{closure#0}>::{closure#0})>::{closure#0}, char, &str, char, alloc::string::String>::{closure#0}, alloc::borrow::Cow<str>::Owned>::{closure#0}, nom::combinator::map<&str, &str, alloc::borrow::Cow<str>, nom::error::Error<&str>, nom::bytes::complete::tag<&str, &str, nom::error::Error<&str>>::{closure#0}, alloc::borrow::Cow<str>::Borrowed>::{closure#0})>::{closure#0}, nom::character::complete::char<&str, nom::error::Error<&str>>::{closure#0}>::{closure#0}, nom::combinator::map<&str, &str, alloc::borrow::Cow<str>, nom::error::Error<&str>, nom::sequence::delimited<&str, char, &str, char, nom::error::Error<&str>, nom::character::complete::char<&str, nom::error::Error<&str>>::{closure#0}, nom::branch::alt<&str, &str, nom::error::Error<&str>, (nom::bytes::complete::is_not<&str, &str, nom::error::Error<&str>>::{closure#0}, nom::bytes::complete::tag<&str, &str, nom::error::Error<&str>>::{closure#0})>::{closure#0}, nom::character::complete::char<&str, nom::error::Error<&str>>::{closure#0}>::{closure#0}, alloc::borrow::Cow<str>::Borrowed>::{closure#0}, nom::combinator::map<&str, &str, alloc::borrow::Cow<str>, nom::error::Error<&str>, nom::bytes::complete::take_while1<serde_keyvalue::key_values::any_string::{closure#0}, &str, nom::error::Error<&str>>::{closure#0}, alloc::borrow::Cow<str>::Borrowed>::{closure#0}) as nom::branch::Alt<&str, alloc::borrow::Cow<str>, nom::error::Error<&str>>>::choice
Unexecuted instantiation: <(nom::combinator::value<&str, u32, &str, nom::error::Error<&str>, nom::bytes::complete::tag<&str, &str, nom::error::Error<&str>>::{closure#0}>::{closure#0}, nom::combinator::value<&str, u32, &str, nom::error::Error<&str>, nom::bytes::complete::tag<&str, &str, nom::error::Error<&str>>::{closure#0}>::{closure#0}, nom::combinator::value<&str, u32, &str, nom::error::Error<&str>, nom::bytes::complete::tag<&str, &str, nom::error::Error<&str>>::{closure#0}>::{closure#0}) as nom::branch::Alt<&str, u32, nom::error::Error<&str>>>::choice
Unexecuted instantiation: <(nom::combinator::map<&str, alloc::string::String, alloc::borrow::Cow<str>, nom::error::Error<&str>, nom::bytes::complete::escaped_transform<&str, nom::error::Error<&str>, nom::character::complete::none_of<&str, &str, nom::error::Error<&str>>::{closure#0}, nom::branch::alt<&str, &str, nom::error::Error<&str>, (nom::combinator::value<&str, &str, char, nom::error::Error<&str>, nom::character::complete::char<&str, nom::error::Error<&str>>::{closure#0}>::{closure#0}, nom::combinator::value<&str, &str, char, nom::error::Error<&str>, nom::character::complete::char<&str, nom::error::Error<&str>>::{closure#0}>::{closure#0})>::{closure#0}, char, &str, char, alloc::string::String>::{closure#0}, alloc::borrow::Cow<str>::Owned>::{closure#0}, nom::combinator::map<&str, &str, alloc::borrow::Cow<str>, nom::error::Error<&str>, nom::bytes::complete::tag<&str, &str, nom::error::Error<&str>>::{closure#0}, alloc::borrow::Cow<str>::Borrowed>::{closure#0}) as nom::branch::Alt<&str, alloc::borrow::Cow<str>, nom::error::Error<&str>>>::choice
Unexecuted instantiation: <(nom::combinator::value<&str, &str, char, nom::error::Error<&str>, nom::character::complete::char<&str, nom::error::Error<&str>>::{closure#0}>::{closure#0}, nom::combinator::value<&str, &str, char, nom::error::Error<&str>, nom::character::complete::char<&str, nom::error::Error<&str>>::{closure#0}>::{closure#0}) as nom::branch::Alt<&str, &str, nom::error::Error<&str>>>::choice
Unexecuted instantiation: <(nom::combinator::value<&str, bool, &str, nom::error::Error<&str>, nom::bytes::complete::tag<&str, &str, nom::error::Error<&str>>::{closure#0}>::{closure#0}, nom::combinator::value<&str, bool, &str, nom::error::Error<&str>, nom::bytes::complete::tag<&str, &str, nom::error::Error<&str>>::{closure#0}>::{closure#0}) as nom::branch::Alt<&str, bool, nom::error::Error<&str>>>::choice
Unexecuted instantiation: <(nom::bytes::complete::is_not<&str, &str, nom::error::Error<&str>>::{closure#0}, nom::bytes::complete::tag<&str, &str, nom::error::Error<&str>>::{closure#0}) as nom::branch::Alt<&str, &str, nom::error::Error<&str>>>::choice
Unexecuted instantiation: <(_, _) as nom::branch::Alt<_, _, _>>::choice
Unexecuted instantiation: <(_, _, _) as nom::branch::Alt<_, _, _>>::choice
Unexecuted instantiation: <(_, _, _, _) as nom::branch::Alt<_, _, _>>::choice
Unexecuted instantiation: <(_, _, _, _, _) as nom::branch::Alt<_, _, _>>::choice
Unexecuted instantiation: <(_, _, _, _, _, _) as nom::branch::Alt<_, _, _>>::choice
Unexecuted instantiation: <(_, _, _, _, _, _, _) as nom::branch::Alt<_, _, _>>::choice
Unexecuted instantiation: <(_, _, _, _, _, _, _, _) as nom::branch::Alt<_, _, _>>::choice
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _) as nom::branch::Alt<_, _, _>>::choice
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _) as nom::branch::Alt<_, _, _>>::choice
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _) as nom::branch::Alt<_, _, _>>::choice
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _) as nom::branch::Alt<_, _, _>>::choice
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _) as nom::branch::Alt<_, _, _>>::choice
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _) as nom::branch::Alt<_, _, _>>::choice
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as nom::branch::Alt<_, _, _>>::choice
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as nom::branch::Alt<_, _, _>>::choice
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as nom::branch::Alt<_, _, _>>::choice
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as nom::branch::Alt<_, _, _>>::choice
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as nom::branch::Alt<_, _, _>>::choice
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as nom::branch::Alt<_, _, _>>::choice
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as nom::branch::Alt<_, _, _>>::choice
164
    }
165
  );
166
);
167
168
macro_rules! alt_trait_inner(
169
  ($it:tt, $self:expr, $input:expr, $err:expr, $head:ident $($id:ident)+) => (
170
    match $self.$it.parse($input.clone()) {
171
      Err(Err::Error(e)) => {
172
        let err = $err.or(e);
173
        succ!($it, alt_trait_inner!($self, $input, err, $($id)+))
174
      }
175
      res => res,
176
    }
177
  );
178
  ($it:tt, $self:expr, $input:expr, $err:expr, $head:ident) => (
179
    Err(Err::Error(Error::append($input, ErrorKind::Alt, $err)))
180
  );
181
);
182
183
alt_trait!(A B C D E F G H I J K L M N O P Q R S T U);
184
185
// Manually implement Alt for (A,), the 1-tuple type
186
impl<Input, Output, Error: ParseError<Input>, A: Parser<Input, Output, Error>>
187
  Alt<Input, Output, Error> for (A,)
188
{
189
0
  fn choice(&mut self, input: Input) -> IResult<Input, Output, Error> {
190
0
    self.0.parse(input)
191
0
  }
192
}
193
194
macro_rules! permutation_trait(
195
  (
196
    $name1:ident $ty1:ident $item1:ident
197
    $name2:ident $ty2:ident $item2:ident
198
    $($name3:ident $ty3:ident $item3:ident)*
199
  ) => (
200
    permutation_trait!(__impl $name1 $ty1 $item1, $name2 $ty2 $item2; $($name3 $ty3 $item3)*);
201
  );
202
  (
203
    __impl $($name:ident $ty:ident $item:ident),+;
204
    $name1:ident $ty1:ident $item1:ident $($name2:ident $ty2:ident $item2:ident)*
205
  ) => (
206
    permutation_trait_impl!($($name $ty $item),+);
207
    permutation_trait!(__impl $($name $ty $item),+ , $name1 $ty1 $item1; $($name2 $ty2 $item2)*);
208
  );
209
  (__impl $($name:ident $ty:ident $item:ident),+;) => (
210
    permutation_trait_impl!($($name $ty $item),+);
211
  );
212
);
213
214
macro_rules! permutation_trait_impl(
215
  ($($name:ident $ty:ident $item:ident),+) => (
216
    impl<
217
      Input: Clone, $($ty),+ , Error: ParseError<Input>,
218
      $($name: Parser<Input, $ty, Error>),+
219
    > Permutation<Input, ( $($ty),+ ), Error> for ( $($name),+ ) {
220
221
0
      fn permutation(&mut self, mut input: Input) -> IResult<Input, ( $($ty),+ ), Error> {
222
0
        let mut res = ($(Option::<$ty>::None),+);
223
224
0
        loop {
225
0
          let mut err: Option<Error> = None;
226
0
          permutation_trait_inner!(0, self, input, res, err, $($name)+);
227
228
          // If we reach here, every iterator has either been applied before,
229
          // or errored on the remaining input
230
0
          if let Some(err) = err {
231
            // There are remaining parsers, and all errored on the remaining input
232
0
            return Err(Err::Error(Error::append(input, ErrorKind::Permutation, err)));
233
0
          }
234
235
          // All parsers were applied
236
0
          match res {
237
0
            ($(Some($item)),+) => return Ok((input, ($($item),+))),
238
0
            _ => unreachable!(),
239
          }
240
        }
241
0
      }
Unexecuted instantiation: <(_, _) as nom::branch::Permutation<_, (_, _), _>>::permutation
Unexecuted instantiation: <(_, _, _) as nom::branch::Permutation<_, (_, _, _), _>>::permutation
Unexecuted instantiation: <(_, _, _, _) as nom::branch::Permutation<_, (_, _, _, _), _>>::permutation
Unexecuted instantiation: <(_, _, _, _, _) as nom::branch::Permutation<_, (_, _, _, _, _), _>>::permutation
Unexecuted instantiation: <(_, _, _, _, _, _) as nom::branch::Permutation<_, (_, _, _, _, _, _), _>>::permutation
Unexecuted instantiation: <(_, _, _, _, _, _, _) as nom::branch::Permutation<_, (_, _, _, _, _, _, _), _>>::permutation
Unexecuted instantiation: <(_, _, _, _, _, _, _, _) as nom::branch::Permutation<_, (_, _, _, _, _, _, _, _), _>>::permutation
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _) as nom::branch::Permutation<_, (_, _, _, _, _, _, _, _, _), _>>::permutation
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _) as nom::branch::Permutation<_, (_, _, _, _, _, _, _, _, _, _), _>>::permutation
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _) as nom::branch::Permutation<_, (_, _, _, _, _, _, _, _, _, _, _), _>>::permutation
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _) as nom::branch::Permutation<_, (_, _, _, _, _, _, _, _, _, _, _, _), _>>::permutation
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _) as nom::branch::Permutation<_, (_, _, _, _, _, _, _, _, _, _, _, _, _), _>>::permutation
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _) as nom::branch::Permutation<_, (_, _, _, _, _, _, _, _, _, _, _, _, _, _), _>>::permutation
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as nom::branch::Permutation<_, (_, _, _, _, _, _, _, _, _, _, _, _, _, _, _), _>>::permutation
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as nom::branch::Permutation<_, (_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _), _>>::permutation
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as nom::branch::Permutation<_, (_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _), _>>::permutation
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as nom::branch::Permutation<_, (_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _), _>>::permutation
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as nom::branch::Permutation<_, (_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _), _>>::permutation
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as nom::branch::Permutation<_, (_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _), _>>::permutation
Unexecuted instantiation: <(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) as nom::branch::Permutation<_, (_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _), _>>::permutation
242
    }
243
  );
244
);
245
246
macro_rules! permutation_trait_inner(
247
  ($it:tt, $self:expr, $input:ident, $res:expr, $err:expr, $head:ident $($id:ident)*) => (
248
    if $res.$it.is_none() {
249
      match $self.$it.parse($input.clone()) {
250
        Ok((i, o)) => {
251
          $input = i;
252
          $res.$it = Some(o);
253
          continue;
254
        }
255
        Err(Err::Error(e)) => {
256
          $err = Some(match $err {
257
            Some(err) => err.or(e),
258
            None => e,
259
          });
260
        }
261
        Err(e) => return Err(e),
262
      };
263
    }
264
    succ!($it, permutation_trait_inner!($self, $input, $res, $err, $($id)*));
265
  );
266
  ($it:tt, $self:expr, $input:ident, $res:expr, $err:expr,) => ();
267
);
268
269
permutation_trait!(
270
  FnA A a
271
  FnB B b
272
  FnC C c
273
  FnD D d
274
  FnE E e
275
  FnF F f
276
  FnG G g
277
  FnH H h
278
  FnI I i
279
  FnJ J j
280
  FnK K k
281
  FnL L l
282
  FnM M m
283
  FnN N n
284
  FnO O o
285
  FnP P p
286
  FnQ Q q
287
  FnR R r
288
  FnS S s
289
  FnT T t
290
  FnU U u
291
);