Skip to content

Commit

Permalink
Add a function that can split up a module name in Text, rather than s…
Browse files Browse the repository at this point in the history
…tring
  • Loading branch information
yav committed Oct 11, 2022
1 parent 043bd69 commit 91dbed4
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/Cryptol/Utils/Ident.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module Cryptol.Utils.Ident
, modNameToText
, textToModName
, modNameChunks
, modNameChunksText
, packModName
, preludeName
, preludeReferenceName
Expand Down Expand Up @@ -182,16 +183,21 @@ modNameIsNormal (ModName _ fl) = isNormal fl
textToModName :: T.Text -> ModName
textToModName txt = ModName txt NormalName

modNameChunks :: ModName -> [String]
modNameChunks (ModName x fl) = unfoldr step x
-- | Break up a module name on the separators, `Text` version.
modNameChunksText :: ModName -> [T.Text]
modNameChunksText (ModName x fl) = unfoldr step x
where
step str
| T.null str = Nothing
| otherwise =
case T.breakOn modSep str of
(a,b)
| T.null b -> Just (T.unpack (maybeAnonText fl str), b)
| otherwise -> Just (T.unpack a,T.drop (T.length modSep) b)
| T.null b -> Just (maybeAnonText fl str, b)
| otherwise -> Just (a,T.drop (T.length modSep) b)

-- | Break up a module name on the separators, `String` version
modNameChunks :: ModName -> [String]
modNameChunks = map T.unpack . modNameChunksText

packModName :: [T.Text] -> ModName
packModName strs = textToModName (T.intercalate modSep (map trim strs))
Expand Down

0 comments on commit 91dbed4

Please sign in to comment.