Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
Cabal
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Glasgow Haskell Compiler
Packages
Cabal
Commits
f8eb9aa9
Commit
f8eb9aa9
authored
16 years ago
by
Duncan Coutts
Browse files
Options
Downloads
Patches
Plain Diff
Add ModuleName.fromString and deprecate ModuleName.simple
Also document the functions in the ModuleName module.
parent
e35bdd52
Loading
Loading
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Distribution/ModuleName.hs
+45
-6
45 additions, 6 deletions
Distribution/ModuleName.hs
Distribution/Simple/BuildPaths.hs
+2
-1
2 additions, 1 deletion
Distribution/Simple/BuildPaths.hs
with
47 additions
and
7 deletions
Distribution/ModuleName.hs
+
45
−
6
View file @
f8eb9aa9
...
...
@@ -40,10 +40,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -}
module
Distribution.ModuleName
(
ModuleName
,
simple
,
fromString
,
components
,
toFilePath
,
main
,
simple
,
)
where
import
Distribution.Text
...
...
@@ -57,9 +58,9 @@ import System.FilePath
(
pathSeparator
)
import
Data.List
(
intersperse
)
import
Control.Exception
(
assert
)
-- | A valid Haskell module name.
--
newtype
ModuleName
=
ModuleName
[
String
]
deriving
(
Eq
,
Ord
,
Read
,
Show
)
...
...
@@ -74,18 +75,56 @@ instance Text ModuleName where
where
component
=
do
c
<-
Parse
.
satisfy
Char
.
isUpper
cs
<-
Parse
.
munch
(
\
x
->
Char
.
isAlphaNum
x
||
x
==
'_'
||
x
==
'
\'
'
)
cs
<-
Parse
.
munch
validModuleChar
return
(
c
:
cs
)
validModuleChar
::
Char
->
Bool
validModuleChar
c
=
Char
.
isAlphaNum
c
||
c
==
'_'
||
c
==
'
\'
'
validModuleComponent
::
String
->
Bool
validModuleComponent
[]
=
False
validModuleComponent
(
c
:
cs
)
=
Char
.
isUpper
c
&&
all
validModuleChar
cs
{-# DEPRECATED simple "use ModuleName.fromString instead" #-}
simple
::
String
->
ModuleName
simple
name
=
assert
(
all
(
/=
'.'
)
name
)
(
ModuleName
[
name
])
simple
str
=
ModuleName
[
str
]
-- | Construct a 'ModuleName' from a valid module name 'String'.
--
-- This is just a convenience function intended for valid module strings. It is
-- an error if it is used with a string that is not a valid module name. If you
-- are parsing user input then use 'Distribution.Text.simpleParse' instead.
--
fromString
::
String
->
ModuleName
fromString
string
|
all
validModuleComponent
components'
=
ModuleName
components'
|
otherwise
=
error
badName
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
-- | The module name @Main@.
--
main
::
ModuleName
main
=
ModuleName
[
"Main"
]
-- | The individual components of a hierarchical module name. For example
--
-- > components (fromString "A.B.C") = ["A", "B", "C"]
--
components
::
ModuleName
->
[
String
]
components
(
ModuleName
ms
)
=
ms
-- | Convert a module name to a file path, but without any file extension.
-- For example:
--
-- > toFilePath (fromString "A.B.C") = "A/B/C"
--
toFilePath
::
ModuleName
->
FilePath
toFilePath
=
concat
.
intersperse
[
pathSeparator
]
.
components
This diff is collapsed.
Click to expand it.
Distribution/Simple/BuildPaths.hs
+
2
−
1
View file @
f8eb9aa9
...
...
@@ -98,7 +98,8 @@ cppHeaderName = "cabal_macros.h"
-- |The name of the auto-generated module associated with a package
autogenModuleName
::
PackageDescription
->
ModuleName
autogenModuleName
pkg_descr
=
ModuleName
.
simple
$
"Paths_"
++
map
fixchar
(
display
(
packageName
pkg_descr
))
ModuleName
.
fromString
$
"Paths_"
++
map
fixchar
(
display
(
packageName
pkg_descr
))
where
fixchar
'-'
=
'_'
fixchar
c
=
c
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment