Commit a7cc266a authored by Oleg Grenrus's avatar Oleg Grenrus
Browse files

Add ModuleName.fromComponents

parent 6dea5762
......@@ -15,6 +15,7 @@
module Distribution.ModuleName (
ModuleName,
fromString,
fromComponents,
components,
toFilePath,
main,
......@@ -74,18 +75,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