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
//! Parser combinators for matching literals.
use crate*;
/// Match an empty portion of the input.
///
/// ```
/// # use glue::prelude::*;
/// // Match "foo bar" or "foobar":
/// let mut parser = find_any((
/// find_all((is("foo"), is(" "), is("bar"))),
/// find_all((is("foo"), empty(), is("bar"))),
/// ));
///
/// assert_eq!(
/// parser.parse("foobar"),
/// Ok((
/// ParserContext {
/// input: "foobar",
/// bounds: 0..6
/// },
/// ("foo", "", "bar"),
/// ))
/// );
/// assert_eq!(
/// parser.parse("foo bar"),
/// Ok((
/// ParserContext {
/// input: "foo bar",
/// bounds: 0..7
/// },
/// ("foo", " ", "bar"),
/// ))
/// );
/// ```
/// Match the end of input.
///
/// ```
/// # use glue::prelude::*;
/// // Match the "foo" in "foo" or "foobar":
/// let mut parser = find_any((
/// find_all((is("foo"), eoi())),
/// find_all((is("foo"), empty())),
/// ));
///
/// assert_eq!(
/// parser.parse("foo"),
/// Ok((
/// ParserContext {
/// input: "foo",
/// bounds: 0..3,
/// },
/// ("foo", ""),
/// ))
/// );
/// assert_eq!(
/// parser.parse("foobar"),
/// Ok((
/// ParserContext {
/// input: "foobar",
/// bounds: 0..3,
/// },
/// ("foo", "")
/// ))
/// );
/// ```
/// Match using a string or character literal, callback or implementation of [`MatchParser`](crate::testers::MatchParser).
///
/// Can be used to match from a list of characters:
///
/// ```
/// # use glue::prelude::*;
/// assert!(is(one_of("abcdef")).test("foobar"));
/// // Or:
/// assert!(is("abcdef".chars()).test("foobar"));
/// ```
///
/// A function that takes a character as input:
///
/// ```
/// # use glue::prelude::*;
/// assert!(is(alphabetic).test("foobar"));
/// ```
///
/// A character literal:
///
/// ```
/// # use glue::prelude::*;
/// assert!(is('f').test("foobar"));
/// ```
///
/// A string literal:
///
/// ```
/// # use glue::prelude::*;
/// assert_eq!(
/// is("foobar").parse("foobar"),
/// Ok((
/// ParserContext {
/// input: "foobar",
/// bounds: 0..6,
/// },
/// "foobar"
/// ))
/// );
/// ```
/// Match negatively using a string or character literal, callback or implementation of [`MatchParser`](crate::testers::MatchParser).
///
/// The same as [`is`] but with the test negated.
///
/// Can be used to match from a list of characters:
///
/// ```
/// # use glue::prelude::*;
/// assert!(isnt(one_of("xyz")).test("foobar"));
/// // Or:
/// assert!(isnt("xyz".chars()).test("foobar"));
/// ```
///
/// A function that takes a character as input:
///
/// ```
/// # use glue::prelude::*;
/// assert!(isnt(numeric).test("foobar"));
/// ```
///
/// A character literal:
///
/// ```
/// # use glue::prelude::*;
/// assert!(isnt('z').test("foobar"));
/// ```
///
/// A string literal:
///
/// ```
/// # use glue::prelude::*;
/// assert!(isnt("boofar").test("foobar"));
/// ```
/// Match the next character against one of these characters.
///
/// ```
/// # use glue::prelude::*;
/// assert!(is(one_of("abcdef")).test("foobar"));
/// ```
/// Match the start of input.
///
/// ```
/// # use glue::prelude::*;
/// assert_eq!(soi().test("foobar"), true);
/// assert_eq!(find_all((is("foobar"), soi())).test("foobar"), false);
/// ```