Skip to content

Commit c160c90

Browse files
committed
Docs
1 parent 66cb917 commit c160c90

File tree

2 files changed

+36
-21
lines changed

2 files changed

+36
-21
lines changed

src/Parsing/String.purs

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
-- | Primitive parsers for working with an input stream of type `String`.
22
-- |
3-
-- | All of these primitive parsers will consume their input when they succeed.
3+
-- | All of these primitive parsers will consume when they succeed.
44
-- |
5-
-- | All of these primitive parsers will consume no input when they
5+
-- | All of these primitive parsers will not consume when they
66
-- | fail.
77
-- |
88
-- | The behavior of these primitive parsers is based on the behavior of the
@@ -204,28 +204,42 @@ match p = do
204204
-- boundary.
205205
pure $ Tuple (SCU.take (SCU.length input1 - SCU.length input2) input1) x
206206

207-
-- | Compile a regular expression string into a regular expression parser.
207+
-- | Compile a regular expression `String` into a regular expression parser.
208208
-- |
209-
-- | This function will use the `Data.String.Regex.regex` function to compile and return a parser which can be used
209+
-- | This function will use the `Data.String.Regex.regex` function to compile
210+
-- | and return a parser which can be used
210211
-- | in a `ParserT String m` monad.
212+
-- | If compilation fails then this function will return `Left` a compilation
213+
-- | error message.
214+
-- |
215+
-- | The returned parser will try to match the regular expression pattern once,
216+
-- | starting at the current parser position. On success, it will return
217+
-- | the matched substring.
218+
-- |
219+
-- | If the RegExp `String` is constant then we can assume that compilation will
220+
-- | always succeed and `unsafeCrashWith` if it doesn’t. If we dynamically
221+
-- | generate the RegExp `String` at runtime then we should handle the
222+
-- | case where compilation of the RegExp fails.
223+
-- |
224+
-- | This function should be called outside the context of a `ParserT String m`
225+
-- | monad for two reasons:
226+
-- | 1. If we call this function inside of the `ParserT String m` monad and
227+
-- | then `fail` the parse when the compilation fails,
228+
-- | then that could be confusing because a parser failure is supposed to
229+
-- | indicate an invalid input string.
230+
-- | If the compilation failure occurs in an `alt` then the compilation
231+
-- | failure might not be reported at all and instead
232+
-- | the input string would be parsed incorrectly.
233+
-- | 2. Compiling a RegExp is expensive and it’s better to do it
234+
-- | once in advance and then use the compiled RegExp many times than
235+
-- | to compile the RegExp many times during the parse.
211236
-- |
212-
-- | This parser will try to match the regular expression pattern starting
213-
-- | at the current parser position. On success, it will return the matched
214-
-- | substring.
237+
-- | This parser may be useful for quickly consuming a large section of the
238+
-- | input `String`, because in a JavaScript runtime environment a compiled
239+
-- | RegExp is a lot faster than a monadic parser built from parsing primitives.
215240
-- |
216241
-- | [*MDN Regular Expressions Cheatsheet*](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Cheatsheet)
217242
-- |
218-
-- | This function should be called outside the context of a `ParserT String m` monad, because this function might
219-
-- | fail with a `Left` RegExp compilation error message.
220-
-- | If you call this function inside of the `ParserT String m` monad and then `fail` the parse when the compilation fails,
221-
-- | then that could be confusing because a parser failure is supposed to indicate an invalid input string.
222-
-- | If the compilation failure occurs in an `alt` then the compilation failure might not be reported at all and instead
223-
-- | the input string would be parsed incorrectly.
224-
-- |
225-
-- | This parser may be useful for quickly consuming a large section of the
226-
-- | input `String`, because in a JavaScript runtime environment the RegExp
227-
-- | runtime is a lot faster than primitive parsers.
228-
-- |
229243
-- | #### Example
230244
-- |
231245
-- | This example shows how to compile and run the `xMany` parser which will
@@ -246,7 +260,8 @@ match p = do
246260
-- | regex "x*" (dotAll <> ignoreCase)
247261
-- | ```
248262
-- |
249-
-- | The `dotAll`, `unicode`, and `ignoreCase` flags might make sense for a `regex` parser. The other flags will
263+
-- | The `dotAll`, `unicode`, and `ignoreCase` flags might make sense for
264+
-- | a `regex` parser. The other flags will
250265
-- | probably cause surprising behavior and you should avoid them.
251266
-- |
252267
-- | [*MDN Advanced searching with flags*](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#advanced_searching_with_flags)

src/Parsing/String/Replace.purs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,8 +422,8 @@ splitCap input sep = unwrap $ splitCapT input sep
422422
-- | ```purescript
423423
-- | replaceT "◀ {HOME} ▶" do
424424
-- | _ <- string "{"
425-
-- | Tuple home _ <- anyTill (string "}")
426-
-- | lift (lookupEnv home) >>= maybe empty pure
425+
-- | Tuple variable _ <- anyTill (string "}")
426+
-- | lift (lookupEnv variable) >>= maybe empty pure
427427
-- | ```
428428
-- |
429429
-- | Result:

0 commit comments

Comments
 (0)