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
// Copyright 2017 Jeremy Wall <jeremy@marzhillstudios.com>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//! An opinionated parser combinator library with a focus on fully abortable parsing and
//! easy error handling.
//!
//! The approach to macro composition is heavily inspired by nom. It focuses on a simple
//! API for combinators, and easy error handling.
//!
//! We have a number of macros that assist in the gneration or handling of each type
//! of error.
//!
//! # Simple parsing of a url.
//!
//! ```
//! #[macro_use]
//! extern crate abortable_parser;
//! use abortable_parser::iter::StrIter;
//! use abortable_parser::{Result, eoi, ascii_ws};
//!
//! make_fn!(proto<StrIter, &str>,
//! do_each!(
//! proto => until!(text_token!("://")),
//! _ => must!(text_token!("://")),
//! (proto)
//! )
//! );
//!
//! make_fn!(domain<StrIter, &str>,
//! do_each!(
//! // domains do not start with a slash
//! _ => peek!(not!(text_token!("/"))),
//! domain => until!(either!(
//! discard!(text_token!("/")),
//! discard!(ascii_ws),
//! eoi)),
//! (domain)
//! )
//! );
//!
//! make_fn!(path<StrIter, &str>,
//! until!(either!(discard!(ascii_ws), eoi))
//! );
//!
//! make_fn!(full_url<StrIter, (Option<&str>, Option<&str>, Option<&str>)>,
//! do_each!(
//! protocol => proto,
//! // If we match the protocol then we must have a domain.
//! // This is an example of an unrecoverable parsing error so we
//! // abort with the must! macro if it doesn't match.
//! domain => must!(domain),
//! path => optional!(path),
//! (Some(protocol), Some(domain), path)
//! )
//! );
//!
//! make_fn!(relative_url<StrIter, (Option<&str>, Option<&str>, Option<&str>)>,
//! do_each!(
//! _ => not!(either!(text_token!("//"), proto)),
//! // we require a valid path for relative urls.
//! path => path,
//! (None, None, Some(path))
//! )
//! );
//!
//! make_fn!(url<StrIter, (Option<&str>, Option<&str>, Option<&str>)>,
//! either!(
//! full_url,
//! relative_url,
//! )
//! );
//!
//! # fn main() {
//! let iter = StrIter::new("http://example.com/some/path ");
//! let result = url(iter);
//! assert!(result.is_complete());
//! if let Result::Complete(_, (proto, domain, path)) = result {
//! assert!(proto.is_some());
//! assert!(domain.is_some());
//! if let Some(domain) = domain {
//! assert_eq!(domain, "example.com");
//! }
//! assert!(path.is_some());
//! if let Some(path) = path {
//! assert_eq!(path, "/some/path");
//! }
//! }
//!
//! let bad_input = StrIter::new("http:///some/path");
//! let bad_result = url(bad_input);
//! assert!(bad_result.is_abort());
//! # }
//! ```
use ;
use Iterator;
use result;
/// A trait for types that can have an offset as a count of processed items.
/// Trait for Inputs that can report current lines and columns in a text input.
/// SpanRange encompasses the valid Ops::Range types for use with the Span trait.
/// An input that can provide a span of a range of the input.
/// A Cloneable Iterator that can report an offset as a count of processed Items.
/// The custom error type for use in `Result::{Fail, Abort}`.
/// Stores a wrapped err that must implement Display as well as an offset and
/// an optional cause.
/// The result of a parsing attempt.
pub use *;
pub use SliceIter;
pub use StrIter;