switch to Text.Regex.Applicative.Text

so we no longer need to pack and unpack strings manually.
This commit is contained in:
Jan Tojnar 2019-01-18 10:28:36 +01:00
parent 1fd8b1534a
commit 47fb59d482
No known key found for this signature in database
GPG Key ID: 7FAB2A15F7A607A4
3 changed files with 11 additions and 11 deletions

View File

@ -24,7 +24,7 @@ dependencies:
- filepath
- neat-interpolation >= 0.3 && < 0.4
- optparse-applicative
- regex-applicative
- regex-applicative-text
- shelly
- text
- time >= 1.8 && < 1.10

View File

@ -14,8 +14,8 @@ import qualified Data.Text as T
import Prelude hiding (FilePath)
import qualified Shell
import Shelly
import qualified Text.Regex.Applicative as RE
import Text.Regex.Applicative (RE, (=~))
import qualified Text.Regex.Applicative.Text as RE
import Text.Regex.Applicative.Text (RE', (=~))
import Utils (Options(..), UpdateEnv(..), Version)
default (T.Text)
@ -27,9 +27,9 @@ data BinaryCheck = BinaryCheck
}
-- | Construct regex: [^\.]*${version}\.*\s*
versionRegex :: Text -> RE Char ()
versionRegex :: Text -> RE' ()
versionRegex version =
(\_ _ _ _ -> ()) <$> many (RE.psym (/= '.')) <*> RE.string (T.unpack version) <*>
(\_ _ _ _ -> ()) <$> many (RE.psym (/= '.')) <*> RE.string version <*>
many (RE.sym '.') <*>
many (RE.psym isSpace)
@ -43,7 +43,7 @@ checkBinary argument expectedVersion program =
stderr <- lastStderr
let hasVersion =
isJust $
(T.unpack . T.unwords . T.lines $ stdout <> "\n" <> stderr) =~
(T.unwords . T.lines $ stdout <> "\n" <> stderr) =~
versionRegex expectedVersion
return $ BinaryCheck program (code == 0) hasVersion)
(\_ -> return $ BinaryCheck program False False)

View File

@ -14,16 +14,16 @@ import qualified File
import Prelude hiding (FilePath)
import qualified Shell
import Shelly
import qualified Text.Regex.Applicative as RE
import Text.Regex.Applicative (RE, (=~))
import qualified Text.Regex.Applicative.Text as RE
import Text.Regex.Applicative.Text (RE', (=~))
import Utils (UpdateEnv(..), Version)
default (T.Text)
-- | Construct regex: ${version}[^/]+\.(tar|zip)
archiveRegex :: Version -> RE Char ()
archiveRegex :: Version -> RE' ()
archiveRegex version =
(\_ _ _ _ -> ()) <$> RE.string (T.unpack version) <*> some (RE.psym (/= '/')) <*>
(\_ _ _ _ -> ()) <$> RE.string version <*> some (RE.psym (/= '/')) <*>
RE.sym '.' <*>
(RE.string "tar" <|> RE.string "zip")
@ -80,7 +80,7 @@ fixSrcUrl updateEnv derivationFile attrPath oldSrcUrl = do
filter
(\url ->
newVersion updateEnv `T.isInfixOf` url &&
isNothing (T.unpack url =~ archiveRegex (newVersion updateEnv))) &
isNothing (url =~ archiveRegex (newVersion updateEnv))) &
map (T.replace "\"" "")
forResult <-
runExceptT $