Skip to content

Commit 9cdd301

Browse files
committed
regex docs and tests
1 parent aa1e2b3 commit 9cdd301

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/Text/Parsing/Parser/String.purs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,12 +225,18 @@ unCodePoint = unsafeCoerce
225225
-- | at the current parser position. On success, it will return the matched
226226
-- | substring.
227227
-- |
228+
-- | If the `Regex` pattern string fails to compile then this parser will fail.
229+
-- | (Note: It’s not possible to use a precompiled `Regex` because this parser
230+
-- | must set flags and make adjustments to the `Regex` pattern string.)
231+
-- |
228232
-- | This parser may be useful for quickly consuming a large section of the
229233
-- | input `String`, because in a JavaScript runtime environment the `RegExp`
230234
-- | runtime is a lot faster than primitive parsers.
231235
-- |
232236
-- | [*MDN Regular Expressions Cheatsheet*](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Cheatsheet)
233237
-- |
238+
-- | #### Flags
239+
-- |
234240
-- | The `Record flags` argument to the parser is for `Regex` flags. Here are
235241
-- | the default flags.
236242
-- |
@@ -249,10 +255,6 @@ unCodePoint = unsafeCoerce
249255
-- | and use of the other flags may cause strange behavior in the parser.
250256
-- |
251257
-- | [*MDN Advanced searching with flags*](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#advanced_searching_with_flags)
252-
-- |
253-
-- | If the `Regex` pattern string fails to compile then this parser will fail.
254-
-- | (Note: It’s not possible to use a precompiled `Regex` because this parser
255-
-- | must set flags and make adjustments to the `Regex` pattern string.)
256258
regex
257259
:: forall m flags f_
258260
. Monad m

test/Main.purs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,8 @@ main = do
688688
parseTest "regexregex" "regexregex" (regex {} "(regex)*")
689689
parseTest "regexregex" "regex" (regex {} "(^regex)*")
690690
parseTest "ReGeX" "ReGeX" (regex { ignoreCase: true } "regex")
691+
parseTest "regexcapregexcap" "regexcap" (regex {} "(?<CaptureGroupName>regexcap)")
692+
parseTest "regexcapregexcap" "regexcap" (regex {} "(((?<CaptureGroupName>(r)e(g)excap)))")
691693

692694
-- Maybe it is nonsense to allow multiline regex.
693695
-- Because an end-of-line regex pattern `$` will match but then the

0 commit comments

Comments
 (0)