1
1
## Module Text.Parsing.Parser.Combinators
2
2
3
+ Combinators for creating parsers.
4
+
3
5
#### ` (<?>) `
4
6
5
7
``` purescript
8
10
9
11
_ left-associative / precedence -1_
10
12
13
+ Provide an error message in the case of failure.
14
+
11
15
#### ` between `
12
16
13
17
``` purescript
14
18
between :: forall m s a open close. (Monad m) => ParserT s m open -> ParserT s m close -> ParserT s m a -> ParserT s m a
15
19
```
16
20
21
+ Wrap a parser with opening and closing markers.
22
+
23
+ For example:
24
+
25
+ ``` purescript
26
+ parens = between (string "(") (string ")")
27
+ ```
28
+
17
29
#### ` option `
18
30
19
31
``` purescript
20
32
option :: forall m s a. (Monad m) => a -> ParserT s m a -> ParserT s m a
21
33
```
22
34
35
+ Provide a default result in the case where a parser fails without consuming input.
36
+
23
37
#### ` optional `
24
38
25
39
``` purescript
26
40
optional :: forall m s a. (Monad m) => ParserT s m a -> ParserT s m Unit
27
41
```
28
42
43
+ Optionally parse something, failing quietly.
44
+
29
45
#### ` optionMaybe `
30
46
31
47
``` purescript
32
- optionMaybe :: forall m s a. (Functor m, Monad m) => ParserT s m a -> ParserT s m (Maybe a)
48
+ optionMaybe :: forall m s a. (Monad m) => ParserT s m a -> ParserT s m (Maybe a)
33
49
```
34
50
51
+ Return ` Nothing ` in the case where a parser fails without consuming input.
52
+
35
53
#### ` try `
36
54
37
55
``` purescript
38
56
try :: forall m s a. (Functor m) => ParserT s m a -> ParserT s m a
39
57
```
40
58
59
+ In case of failure, reset the stream to the unconsumed state.
60
+
41
61
#### ` sepBy `
42
62
43
63
``` purescript
44
64
sepBy :: forall m s a sep. (Monad m) => ParserT s m a -> ParserT s m sep -> ParserT s m (List a)
45
65
```
46
66
67
+ Parse phrases delimited by a separator.
68
+
69
+ For example:
70
+
71
+ ``` purescript
72
+ digit `sepBy` string ","
73
+ ```
74
+
47
75
#### ` sepBy1 `
48
76
49
77
``` purescript
50
78
sepBy1 :: forall m s a sep. (Monad m) => ParserT s m a -> ParserT s m sep -> ParserT s m (List a)
51
79
```
52
80
81
+ Parse phrases delimited by a separator, requiring at least one match.
82
+
53
83
#### ` sepEndBy `
54
84
55
85
``` purescript
56
86
sepEndBy :: forall m s a sep. (Monad m) => ParserT s m a -> ParserT s m sep -> ParserT s m (List a)
57
87
```
58
88
89
+ Parse phrases delimited and optionally terminated by a separator.
90
+
59
91
#### ` sepEndBy1 `
60
92
61
93
``` purescript
62
94
sepEndBy1 :: forall m s a sep. (Monad m) => ParserT s m a -> ParserT s m sep -> ParserT s m (List a)
63
95
```
64
96
97
+ Parse phrases delimited and optionally terminated by a separator, requiring at least one match.
98
+
65
99
#### ` endBy1 `
66
100
67
101
``` purescript
68
102
endBy1 :: forall m s a sep. (Monad m) => ParserT s m a -> ParserT s m sep -> ParserT s m (List a)
69
103
```
70
104
105
+ Parse phrases delimited and terminated by a separator, requiring at least one match.
106
+
71
107
#### ` endBy `
72
108
73
109
``` purescript
74
110
endBy :: forall m s a sep. (Monad m) => ParserT s m a -> ParserT s m sep -> ParserT s m (List a)
75
111
```
76
112
113
+ Parse phrases delimited and terminated by a separator.
114
+
77
115
#### ` chainr `
78
116
79
117
``` purescript
80
118
chainr :: forall m s a. (Monad m) => ParserT s m a -> ParserT s m (a -> a -> a) -> a -> ParserT s m a
81
119
```
82
120
121
+ Parse phrases delimited by a right-associative operator.
122
+
123
+ For example:
124
+
125
+ ``` purescript
126
+ chainr digit (string "+" *> add) 0
127
+ ```
128
+
83
129
#### ` chainl `
84
130
85
131
``` purescript
86
132
chainl :: forall m s a. (Monad m) => ParserT s m a -> ParserT s m (a -> a -> a) -> a -> ParserT s m a
87
133
```
88
134
135
+ Parse phrases delimited by a left-associative operator.
136
+
89
137
#### ` chainl1 `
90
138
91
139
``` purescript
92
140
chainl1 :: forall m s a. (Monad m) => ParserT s m a -> ParserT s m (a -> a -> a) -> ParserT s m a
93
141
```
94
142
143
+ Parse phrases delimited by a left-associative operator, requiring at least one match.
144
+
95
145
#### ` chainl1' `
96
146
97
147
``` purescript
@@ -104,6 +154,8 @@ chainl1' :: forall m s a. (Monad m) => ParserT s m a -> ParserT s m (a -> a -> a
104
154
chainr1 :: forall m s a. (Monad m) => ParserT s m a -> ParserT s m (a -> a -> a) -> ParserT s m a
105
155
```
106
156
157
+ Parse phrases delimited by a right-associative operator, requiring at least one match.
158
+
107
159
#### ` chainr1' `
108
160
109
161
``` purescript
@@ -116,40 +168,54 @@ chainr1' :: forall m s a. (Monad m) => ParserT s m a -> ParserT s m (a -> a -> a
116
168
choice :: forall f m s a. (Foldable f, Monad m) => f (ParserT s m a) -> ParserT s m a
117
169
```
118
170
171
+ Parse one of a set of alternatives.
172
+
119
173
#### ` skipMany `
120
174
121
175
``` purescript
122
176
skipMany :: forall s a m. (Monad m) => ParserT s m a -> ParserT s m Unit
123
177
```
124
178
179
+ Skip many instances of a phrase.
180
+
125
181
#### ` skipMany1 `
126
182
127
183
``` purescript
128
184
skipMany1 :: forall s a m. (Monad m) => ParserT s m a -> ParserT s m Unit
129
185
```
130
186
187
+ Skip at least one instance of a phrase.
188
+
131
189
#### ` lookAhead `
132
190
133
191
``` purescript
134
192
lookAhead :: forall s a m. (Monad m) => ParserT s m a -> ParserT s m a
135
193
```
136
194
195
+ Parse a phrase, without modifying the consumed state or stream position.
196
+
137
197
#### ` notFollowedBy `
138
198
139
199
``` purescript
140
200
notFollowedBy :: forall s a m. (Monad m) => ParserT s m a -> ParserT s m Unit
141
201
```
142
202
203
+ Fail if the specified parser matches.
204
+
143
205
#### ` manyTill `
144
206
145
207
``` purescript
146
208
manyTill :: forall s a m e. (Monad m) => ParserT s m a -> ParserT s m e -> ParserT s m (List a)
147
209
```
148
210
211
+ Parse several phrases until the specified terminator matches.
212
+
149
213
#### ` many1Till `
150
214
151
215
``` purescript
152
216
many1Till :: forall s a m e. (Monad m) => ParserT s m a -> ParserT s m e -> ParserT s m (List a)
153
217
```
154
218
219
+ Parse several phrases until the specified terminator matches, requiring at least one match.
220
+
155
221
0 commit comments