From 73d9955546d931e42d6280a0a868162a60a85cb9 Mon Sep 17 00:00:00 2001 From: Konstantin Kharlamov Date: Tue, 15 Oct 2024 22:51:05 +0300 Subject: [PATCH] Document that for "usual" regex behavior `multiline` is required MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Regular expression users typically expect that matching a `$` in a multiline string would match the end of current line and not the end of the string past many lines. This is default behavior in pretty much every regexp engine: `grep`, `perl`, text editors, you name it… So it is fair to expect such expectation, so warn a user about necessity to pass `multiline` Fixes: https://github.com/purescript-contrib/purescript-parsing/issues/231 --- src/Parsing/String.purs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Parsing/String.purs b/src/Parsing/String.purs index 29c7652..9bb4e15 100644 --- a/src/Parsing/String.purs +++ b/src/Parsing/String.purs @@ -195,6 +195,9 @@ match p = do -- | Compile a regular expression `String` into a regular expression parser. -- | +-- | Note that per JS RegExp semantics matching a single line in a multiline +-- | string requires passing `multiline` flag rather than `noFlags`. +-- | -- | This function will use the `Data.String.Regex.regex` function to compile -- | and return a parser which can be used -- | in a `ParserT String m` monad. @@ -235,7 +238,7 @@ match p = do -- | capture the regular expression pattern `x*`. -- | -- | ```purescript --- | case regex "x*" noFlags of +-- | case regex "x*" multiline of -- | Left compileError -> unsafeCrashWith $ "xMany failed to compile: " <> compileError -- | Right xMany -> runParser "xxxZ" do -- | xMany