regex-generator 0.1.0.2 → 0.1.0.3
raw patch · 4 files changed
+10/−31 lines, 4 files
Files
- regex-generator.cabal +1/−1
- src/Text/Regex/Regen/Parse.hs +6/−7
- src/Text/Regex/Regen/ParserST.hs +2/−17
- test/Gen.hs +1/−6
regex-generator.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/ name: regex-generator-version: 0.1.0.2+version: 0.1.0.3 synopsis: Generate a random string from a PCRE description: The regex-generator library allows generating bytestrings from PCREs. See github.com/protoben/regex-generator-hs for
src/Text/Regex/Regen/Parse.hs view
@@ -251,12 +251,12 @@ , () <$ string "NO_AUTO_POSSESS" , () <$ string "NO_START_OPT" , () <$ string "BSR_ANYCRLF"- , string "BSR_UNICODE" >> noUnicode- , string "UTF8" >> noUnicode- , string "UTF16" >> noUnicode- , string "UTF32" >> noUnicode- , string "UTF" >> noUnicode- , string "UCP" >> noUnicode+ , () <$ string "UTF8"+ , string "BSR_UNICODE" >> eNotSupported "unicode"+ , string "UTF16" >> eNotSupported "utf16"+ , string "UTF32" >> eNotSupported "utf32"+ , string "UTF" >> eNotSupported "unicode"+ , string "UCP" >> eNotSupported "unicode" , string "CRLF" >> noCRLF , string "ANYCRLF" >> setLineEnds AnyCRLF , string "ANY" >> setLineEnds Any@@ -266,7 +266,6 @@ ] where eBadOpt s = eParserError $ "bad global option: " ++ show s- noUnicode = eNotSupported "unicode" noCRLF = eNotSupported "crlf line ends" localOption :: ParserST ()
src/Text/Regex/Regen/ParserST.hs view
@@ -180,7 +180,7 @@ letter = lift P.letter_ascii hexByte :: ParserST Char-hexByte = inRange $ char 'x' *> (byte' <|> braced byte' <|> pure '\0')+hexByte = char 'x' *> (byte' <|> braced byte' <|> pure '\0') where byte' = byte2 <|> byte1 byte2 = decode <$> hexDigit <*> hexDigit@@ -192,7 +192,7 @@ hexDigitAZ = (\c -> ord c - ord 'A' + 0xA) <$> cInRange 'A' 'Z' octalByte :: ParserST Char-octalByte = inRange $ byte' <|> char 'o' *> (braced byte' <|> eMissingBrace)+octalByte = byte' <|> char 'o' *> (braced byte' <|> eMissingBrace) where octDigit = (\c -> ord c - ord '0') <$> cInRange '0' '7' byte' = byte3 <|> byte2 <|> byte1@@ -201,21 +201,6 @@ byte1 = decode <$> pure 0 <*> pure 0 <*> octDigit decode a b c = chr $ (a * 64) + (b * 8) + c eMissingBrace = eParserError "missing '{' after '\\o'"--inRange :: ParserST Char -> ParserST Char-inRange p = p >>= \c ->- if '\x00' <= c && c <= '\x7f'- then pure c- else eParserError- $ showString "octal and hex escapes must be in range "- $ showRange '\x00' '\x7f' ""- where- showHex' c = showString "0x" . zeroPad 2 (showHex (ord c) "")- showOct' c = zeroPad 3 $ showOct (ord c) ""- zeroPad n s = showString (replicate (n - length s) '0') . showString s- showHexR c d = showHex' c . showString "-" . showHex' d- showOctR c d = showOct' c . showString "-" . showOct' d- showRange c d = showHexR c d . showString " (" . showOctR c d . showString ")" cescape :: ParserST Char cescape = choice
test/Gen.hs view
@@ -54,10 +54,6 @@ it "accepts whitespace escape" $ shouldGen "\\R" it "accepts C escapes" $ shouldGen "\\a\\n\\f\\t" it "accepts escaped specials" $ shouldGen "\\[\\(\\|\\$\\^\\.\\*"- it "rejects out-of-range hex escapes" $- generate "\\x80" `shouldThrow` isEParserError- it "rejects out-of-range octal escapes" $- generate "\\200" `shouldThrow` isEParserError it "rejects '\\C'" $ generate "\\C" `shouldThrow` isENotSupported it "rejects '\\X'" $@@ -230,6 +226,7 @@ it "ignores 'NO_AUTO_POSSESS'" $ shouldGen "(*NO_AUTO_POSSESS)foo" it "ignores 'NO_START_OPT'" $ shouldGen "(*NO_START_OPT)foo" it "ignores 'BSR_ANYCRLF'" $ shouldGen "(*BSR_ANYCRLF)foo"+ it "allows 'UTF8'" $ shouldGen "(*UTF8)foo" it "allows 'LF'" $ shouldGen "(*LF)foo" it "allows 'CR'" $ shouldGen "(*CR)foo" it "allows 'ANY'" $ shouldGen "(*ANY)foo"@@ -238,8 +235,6 @@ generate "(*CRLF)foo" `shouldThrow` isENotSupported it "rejects 'BSR_UNICODE'" $ generate "(*BSR_UNICODE)foo" `shouldThrow` isENotSupported- it "rejects 'UTF8'" $- generate "(*UTF8)foo" `shouldThrow` isENotSupported it "rejects 'UTF16'" $ generate "(*UTF16)foo" `shouldThrow` isENotSupported it "rejects 'UTF32'" $