Commit 81768070 authored by Mikhail Glushenkov's avatar Mikhail Glushenkov Committed by GitHub
Browse files

Merge pull request #3948 from phadej/module-name-from-components

Add ModuleName.fromComponents
parents 8c88c52e 048855d2
......@@ -15,10 +15,13 @@
module Distribution.ModuleName (
ModuleName,
fromString,
fromComponents,
components,
toFilePath,
main,
simple,
-- * Internal
validModuleComponent,
) where
import Prelude ()
......@@ -74,18 +77,21 @@ simple str = ModuleName (stlFromStrings [str])
-- are parsing user input then use 'Distribution.Text.simpleParse' instead.
--
fromString :: String -> ModuleName
fromString string
| all validModuleComponent components' = ModuleName (stlFromStrings components')
| otherwise = error badName
fromString string = fromComponents (split string)
where
components' = split string
badName = "ModuleName.fromString: invalid module name " ++ show string
split cs = case break (=='.') cs of
(chunk,[]) -> chunk : []
(chunk,_:rest) -> chunk : split rest
-- | Construct a 'ModuleName' from valid module components, i.e. parts
-- separated by dots.
fromComponents :: [String] -> ModuleName
fromComponents components'
| all validModuleComponent components' = ModuleName (stlFromStrings components')
| otherwise = error badName
where
badName = "ModuleName.fromComponents: invalid components " ++ show components'
-- | The module name @Main@.
--
main :: ModuleName
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment