Skip to content

Commit

Permalink
text qualified as T, part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-martin committed Oct 20, 2023
1 parent a6d4464 commit dd4a8df
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 29 deletions.
6 changes: 3 additions & 3 deletions cabal-file-inspector/exe-lib/Exe/CabalFileSource.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ data CabalFileSource fp
showCabalFileSource :: CabalFileSource fp -> String
showCabalFileSource = \case
StandardInputCabalFile -> "<stdin>"
CabalFilePath x -> Text.unpack x.text
CabalFilePath x -> T.unpack x.text

-- | Optparse reader for a file path
--
-- This is parameterized on the 'Input' because different systems can have different
-- rules for what constitutes a valid file path.
filePathReader :: Input fp m -> ReadM (FilePath fp)
filePathReader i = maybeReader \s -> let t = Text.pack s in FilePath t <$> i.textFilePath t
filePathReader i = maybeReader \s -> let t = T.pack s in FilePath t <$> i.textFilePath t

cabalParseError :: CabalFileSource fp -> PError -> Error
cabalParseError cabalFileSource = Error . Text.pack . showPError (showCabalFileSource cabalFileSource)
cabalParseError cabalFileSource = Error . T.pack . showPError (showCabalFileSource cabalFileSource)

-- | Fetch the bytes of .cabal file, and parse
--
Expand Down
2 changes: 1 addition & 1 deletion cabal-file-inspector/exe-lib/Exe/Command/Dependencies.hs
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,4 @@ getPackage i opt =
)

printDependencies :: Set PackageName -> IO ()
printDependencies = traverse_ (Text.putStrLn . CabalFile.toText)
printDependencies = traverse_ (T.putStrLn . CabalFile.toText)
8 changes: 4 additions & 4 deletions cabal-file-inspector/exe-lib/Exe/Compiler.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Prelude (Int)
-- This matters because a .cabal file can include conditionals based on information
-- about the compiler.
compilerReader :: ReadM CompilerId
compilerReader = maybeReader $ compilerFromText . Text.pack
compilerReader = maybeReader $ compilerFromText . T.pack

compilerFromText :: Text -> Maybe CompilerId
compilerFromText s =
Expand All @@ -29,10 +29,10 @@ compilerFromText s =
versionFromText versionText <&> CompilerId (compilerFlavorFromText flavorText)

compilerFlavorFromText :: Text -> CompilerFlavor
compilerFlavorFromText = Text.unpack >>> classifyCompilerFlavor
compilerFlavorFromText = T.unpack >>> classifyCompilerFlavor

versionFromText :: Text -> Maybe Version
versionFromText = Text.split (== '.') >>> traverse versionPartFromText >>> fmap mkVersion
versionFromText = T.split (== '.') >>> traverse versionPartFromText >>> fmap mkVersion

versionPartFromText :: Text -> Maybe Int
versionPartFromText = textReadOnly Text.decimal
versionPartFromText = textReadOnly T.decimal
12 changes: 6 additions & 6 deletions cabal-file-inspector/exe-lib/Exe/ComponentSpecification.hs
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@ data ComponentSetSpecification = ComponentSetSpecification

-- | Prints a component in the same format that 'componentsReader' reads
showComponent :: QualifiedComponentName -> Text
showComponent (t :/ n) = Text.concat [componentTypeName t, ":", toText n]
showComponent (t :/ n) = T.concat [componentTypeName t, ":", toText n]

-- | Optparse reader in the form "(lib|flib|test|exe|bench):component-name"
componentsReader :: ReadM (Set QualifiedComponentName)
componentsReader = maybeReader $ componentSetFromText . Text.pack
componentsReader = maybeReader $ componentSetFromText . T.pack

componentSetFromText :: Text -> Maybe (Set QualifiedComponentName)
componentSetFromText =
Text.split (flip (elem @[]) " ,")
>>> filter (not . Text.null)
T.split (flip (elem @[]) " ,")
>>> filter (not . T.null)
>>> traverse componentFromText
>>> fmap Set.fromList

Expand Down Expand Up @@ -113,7 +113,7 @@ resolveComponentSet setSpec package =
missingComponentsError :: NonEmpty QualifiedComponentName -> Error
missingComponentsError missing =
Error $
Text.concat
T.concat
[ "Missing components: "
, Text.intercalate ", " (showComponent <$> toList missing)
, T.intercalate ", " (showComponent <$> toList missing)
]
2 changes: 1 addition & 1 deletion cabal-file-inspector/exe-lib/Exe/Error.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ newtype Error = Error {text :: Text}

-- | Print error texts one-per-line on the standard error stream, then exit with a failure code
errorQuit :: NonEmpty Error -> IO a
errorQuit xs = traverse_ (Text.hPutStrLn stderr) ((.text) <$> xs) *> exitFailure
errorQuit xs = traverse_ (T.hPutStrLn stderr) ((.text) <$> xs) *> exitFailure
6 changes: 3 additions & 3 deletions cabal-file-inspector/exe-lib/Exe/Flags.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ import Prelude (Char)
--
-- "+flagname" set a flag to True; "-flagname" sets it to false.
flagsReader :: ReadM (Map FlagName Bool)
flagsReader = maybeReader $ flagMapFromText . Text.pack
flagsReader = maybeReader $ flagMapFromText . T.pack

flagMapFromText :: Text -> Maybe (Map FlagName Bool)
flagMapFromText =
Text.split (flip (elem @[]) " ,")
T.split (flip (elem @[]) " ,")
>>> traverse flagFromText
>>> fmap Map.fromList

flagFromText :: Text -> Maybe (FlagName, Bool)
flagFromText a = do
(x, y) <- Text.uncons a
(x, y) <- T.uncons a
s <- boolFromFlagChar x
Just (fromText y, s)

Expand Down
2 changes: 1 addition & 1 deletion cabal-file-inspector/exe-lib/Exe/Input.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ data Input fp m = Input
regularInput :: Input OsPath IO
regularInput =
Input
{ textFilePath = Text.unpack >>> OsPath.encodeUtf
{ textFilePath = T.unpack >>> OsPath.encodeUtf
, readStandardInput = hGetContents stdin
, readFile = IO.readFile'
, doesFileExist = doesFileExist
Expand Down
10 changes: 5 additions & 5 deletions cabal-file-inspector/exe-lib/Exe/Text.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ import Prelude (Char, const, either)
-- Fails if no character in the input text satisfies the predicate.
splitIn2 :: (Char -> Bool) -> Text -> Maybe (Text, Text)
splitIn2 f =
Text.break f >>> \(x, y) ->
if Text.null y then Nothing else Just (x, Text.drop 1 y)
T.break f >>> \(x, y) ->
if T.null y then Nothing else Just (x, T.drop 1 y)

-- | Run a 'Text.Reader', requiring that it read the entire input, discarding error information
textReadOnly :: Text.Reader a -> Text -> Maybe a
-- | Run a 'T.Reader', requiring that it read the entire input, discarding error information
textReadOnly :: T.Reader a -> Text -> Maybe a
textReadOnly r t =
r t
& either
(const Nothing)
(\(i, remainder) -> if Text.null remainder then Just i else Nothing)
(\(i, remainder) -> if T.null remainder then Just i else Nothing)
4 changes: 2 additions & 2 deletions cabal-file-inspector/lib/CabalFile/CabalFile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ instance Show e => Show (CabalReadException e) where
-- | Parses like the contents of a .cabal file. Ignores warnings. Bottom if parsing fails.
instance IsString CabalFile where
fromString =
Text.Strict.pack
>>> Text.Strict.encodeUtf8
T.Strict.pack
>>> T.Strict.encodeUtf8
>>> parseCabalFile
>>> (.result)
>>> either (error . show) id
Expand Down
2 changes: 1 addition & 1 deletion cabal-file-inspector/lib/CabalFile/ComponentName.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ instance
instance IsText ComponentName where
string = cabal % Cabal.Optics.componentName_string
shortText = cabal % Cabal.Optics.componentName_shortText
text = string % iso Text.pack Text.unpack
text = string % iso T.pack T.unpack
2 changes: 1 addition & 1 deletion cabal-file-inspector/lib/CabalFile/FlagName.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ instance CabalOptic An_Iso FlagName FlagName Cabal.FlagName Cabal.FlagName where
instance IsText FlagName where
string = cabal % Cabal.Optics.flagName_string
shortText = string % iso Cabal.ShortText.toShortText Cabal.ShortText.fromShortText
text = string % iso Text.pack Text.unpack
text = string % iso T.pack T.unpack
2 changes: 1 addition & 1 deletion cabal-file-inspector/lib/CabalFile/PackageName.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ instance CabalOptic An_Iso PackageName PackageName Cabal.PackageName Cabal.Packa
instance IsText PackageName where
string = cabal % Cabal.Optics.packageName_string
shortText = cabal % Cabal.Optics.packageName_shortText
text = string % iso Text.pack Text.unpack
text = string % iso T.pack T.unpack

0 comments on commit dd4a8df

Please sign in to comment.