You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Combine parse results using a function via map2 through map5
167
167
P.map2((a, b) => a + b, P.anyDigitAsInt, P.anyDigitAsInt)
168
-
|> P.runParser("12") // Belt.Result.Ok(3)
168
+
|> P.runParser("12") // Result.Ok(3)
169
169
170
170
// Combine results from a tuple of parsers using mapTuple2 through mapTuple5
171
171
(P.anyDigitAsInt, P.anyDigitAsInt)
172
172
|> P.mapTuple2((a, b) => a + b)
173
-
|> P.runParser("12"); // Belt.Result.Ok(3)
173
+
|> P.runParser("12"); // Result.Ok(3)
174
174
175
175
// Use the *> operator to run two parsers, and only keep the result from the right side
176
176
// This is useful if you don't care what the left side parser produces (e.g. whitespace)
177
177
// but you need to consume that input.
178
178
// `ws` consumes all the whitespace it encounters and throws it away
179
179
P.ws
180
180
*> P.anyDigit
181
-
|> P.runParser(" 3") // Belt.Result.Ok("3")
181
+
|> P.runParser(" 3") // Result.Ok("3")
182
182
183
183
// Use the <* operator to run two parsers, and only keep the result from the left side
184
184
// This is useful if you don't care what the right side parser produces (e.g. whitespace)
@@ -190,7 +190,7 @@ P.ws
190
190
*> P.anyDigit
191
191
<* P.ws
192
192
<* P.eof
193
-
|> P.runParser(" 3 ") // Belt.Result.Ok("3")
193
+
|> P.runParser(" 3 ") // Result.Ok("3")
194
194
195
195
// ADVANCED: Incrementally collect parse results using a function and chained <$> map and <*> apply
196
196
// operators.
@@ -199,7 +199,7 @@ add3
199
199
<$> P.anyDigitAsInt
200
200
<*> P.anyDigitAsInt
201
201
<*> P.anyDigitAsInt
202
-
|> P.runParser("123"); // Belt.Result.Ok(6)
202
+
|> P.runParser("123"); // Result.Ok(6)
203
203
```
204
204
205
205
Many of these functions and operators come for free for any Applicative via [Relude Apply Extensions](https://github.com/reazen/relude/blob/master/src/extensions/Relude_Extensions_Apply.re)
@@ -225,7 +225,7 @@ if a parser fails at some point in a chain, the rest of the parsers will not run
225
225
// Lift a pure value into a parser.
226
226
// As you can see the parser just produces the given value regardless of the string.
227
227
P.pure(3)
228
-
|> runParser("abcdef") // Belt.Result.Ok(3)
228
+
|> runParser("abcdef") // Result.Ok(3)
229
229
230
230
// Sequence parse operations using flatMap.
231
231
// In this example we read a single digit as an int, then use that value
Many of these functions come for free for any Monad via [Relude Monad Extensions](https://github.com/reazen/relude/blob/master/src/extensions/Relude_Extensions_Monad.re)
@@ -273,7 +273,7 @@ P.anyDigitAsInt
273
273
}
274
274
)
275
275
<#> Relude.List.String.join
276
-
|> runParser("9abc") // Belt.Result.Error(ParseError("The count cannot be >= 5"))
276
+
|> runParser("9abc") // Result.Error(ParseError("The count cannot be >= 5"))
277
277
```
278
278
279
279
The `filter` function in `ReludeParse` is basically for this purpose. Filter produces its
@@ -293,9 +293,9 @@ if it fails, try another, as many times as you want.
293
293
The `<|>` operator is used for this - think of the `<|>` operator as an `orElse` function.
`<|>` can be chained as many times as you want - it attempts each parser left-to-right.
@@ -321,7 +321,7 @@ function to force a parser to back-track all the way to it's original position i
321
321
// parser fully back-track on failure if it had consumed any input.
322
322
P.tries(P.anyDigit *> P.anyDigit) // parse a digit, throw it away, then parse another digit
323
323
<|> (P.anyDigit *> P.anyAlpha) // parse a digit,throw it away, then parse a letter
324
-
|> P.runParser("9a") // Belt.Result.Ok("a")
324
+
|> P.runParser("9a") // Result.Ok("a")
325
325
```
326
326
327
327
# Customizing the error message
@@ -333,7 +333,7 @@ message if the parser fails.
333
333
```reason
334
334
P.many1(P.anyDigit)
335
335
<?> "Expected one or more digits"
336
-
|> P.runParser("abc") // Belt.Result.Error(ParseError("Expected one or more digits"))
336
+
|> P.runParser("abc") // Result.Error(ParseError("Expected one or more digits"))
337
337
```
338
338
339
339
# Checking that all input is consumed
@@ -472,8 +472,8 @@ list of parser functions that come with `ReludeParse`.
472
472
473
473
|Function|Description|Example|
474
474
|--------|-----------|-------|
475
-
|`runParser`|runs a parser with an input string to produce a `Belt.Result` with either the value or a `ParseError.t`
476
-
|`unParser`|runs a parser with an input string to produce a `Belt.Result` with either the value or a `ParseError.t` (with some additional metadata compared to `runParser`)
475
+
|`runParser`|runs a parser with an input string to produce a `Result` with either the value or a `ParseError.t`
476
+
|`unParser`|runs a parser with an input string to produce a `Result` with either the value or a `ParseError.t` (with some additional metadata compared to `runParser`)
0 commit comments