1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
use crate::;
/// Create a parser that always succeeds.
pub const
/// Create a parser that always fails.
pub const
/// Create a parser that parses a single item matching the provided predicate.
///
/// ### Consuming
/// On successful parse
///
/// ### Arguments
/// * `pred` - the predicate
///
/// ### Example
/// ```
/// use anpa::core::*;
/// use anpa::parsers::item_if;
///
/// let parse_uppercase = item_if(|c: char| c.is_uppercase());
/// let input1 = "A";
/// let input2 = "a";
/// assert_eq!(parse(parse_uppercase, input1).result, Some('A'));
/// assert_eq!(parse(parse_uppercase, input2).result, None);
/// ```
pub const
/// Create a parser that parses a single item.
///
/// ### Consuming
/// Always
///
/// ### Example
/// ```
/// use anpa::core::*;
/// use anpa::parsers::item;
///
/// let parse_item = item();
/// let input1 = "x";
/// let input2 = "";
/// assert_eq!(parse(parse_item, input1).result, Some('x'));
/// assert_eq!(parse(parse_item, input2).result, None);
/// ```
pub const
/// Create a parser for matching the provided prefix.
/// Returns the parsed prefix on success.
///
/// If the result is not needed, use [`skip()`] instead.
///
/// The prefix can be anything implementing the [`Prefix`] trait for the parser input.
/// Implementations are provided for single elements and sequences of both `&str`
/// and `&[T]`.
///
/// For performance tuning, consider using the inlined version [`take!`].
///
/// ### Consuming
/// Consumes prefix on successful parse
///
/// ### Arguments
/// * `prefix` - the prefix to match
///
/// ### Example
/// ```
/// use anpa::core::*;
/// use anpa::parsers::take;
///
/// let parse_single = take('a');
/// let parse_seq = take("abc");
/// let input = "abcd";
/// assert_eq!(parse(parse_single, input).result, Some('a'));
/// assert_eq!(parse(parse_seq, input).result, Some("abc"));
/// ```
pub const
/// Create a parser for matching the provided prefix.
///
/// For better performance, this parser should be used if the result isn't saved
/// or inspected.
///
/// The prefix can be anything implementing the [`Prefix`] trait for the parser input.
/// Implementations are provided for single elements and sequences of both `&str`
/// and `&[T]`.
///
/// For performance tuning, consider using the inlined version [`skip!`].
///
/// ### Consuming
/// Consumes prefix on successful parse
///
/// ### Arguments
/// * `prefix` - the prefix to match
///
/// ### Example
/// ```
/// use anpa::core::*;
/// use anpa::parsers::skip;
///
/// let parse_single = skip('a');
/// let parse_seq = skip("abc");
/// let input = "abcd";
/// assert_eq!(parse(parse_single, input).result, Some(()));
/// assert_eq!(parse(parse_seq, input).result, Some(()));
/// ```
pub const
/// Create a parser that parses while the items in the input matches the predicate.
///
/// This parser never fails, so if an empty parse should not be permitted, wrap it in
/// a [`not_empty`](crate::combinators::not_empty) combinator.
///
/// ### Consuming
/// Consumes all matched items.
///
/// ### Arguments
/// * `pred` - the predicate
///
/// ### Example
/// ```
/// use anpa::core::*;
/// use anpa::parsers::item_while;
///
/// let parse_odd = item_while(|n: &u8| n % 2 != 0);
/// let input: &[u8] = &[7, 5, 3, 2];
/// assert_eq!(parse(parse_odd, input).result, Some([7, 5, 3].as_slice()));
/// ```
pub const
/// Create a parser that parses until the input matches the provided argument.
///
/// On a successful parse, all items until the matching needle will be returned.
///
/// The argument can be anything implementing the [`Needle`] trait for the parser input.
/// Implementations are provided for single elements and sequences of both `&str`
/// and `&[T]`.
///
/// For performance tuning, consider using the inlined version [`until!`].
///
/// ### Consuming
/// Consumes all items before the matching needle, and the needle itself.
///
/// ### Arguments
/// * `needle` - the needle to search for
///
/// ### Example
/// ```
/// use anpa::core::*;
/// use anpa::parsers::until;
///
/// let parse_statement = until(';');
/// let input = "let x = 2;";
/// assert_eq!(parse(parse_statement, input).result, Some("let x = 2"));
/// ```
pub const
/// Create a parser that parses the rest of the input. This parser can never fail.
///
/// ### Consuming
/// All input.
///
/// ### Example
/// ```
/// use anpa::core::*;
/// use anpa::parsers::rest;
///
/// let parse_rest = rest();
/// let input = "everything that is left";
/// assert_eq!(parse(parse_rest, input).result, Some(input));
/// ```
pub const
/// Create a parser that is successful only if the input is empty.
/// Returns the empty input on success.
///
/// ### Consuming
/// Nothing
///
/// ### Example
/// ```
/// use anpa::core::*;
/// use anpa::parsers::empty;
///
/// let parse_empty = empty();
/// let input1 = "";
/// let input2 = ".";
/// assert_eq!(parse(parse_empty, input1).result, Some(""));
/// assert_eq!(parse(parse_empty, input2).result, None);
/// ```
pub const