3 -- The above warning supression flag is a temporary kludge.
4 -- While working on this module you are encouraged to remove it and fix
5 -- any warnings in the module. See
6 -- http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#Warnings
9 module ParsePkgConf( loadPackageConfig ) where
11 #include "HsVersions.h"
18 import ErrUtils ( mkLocMessage )
21 import Panic ( GhcException(..) )
22 import Control.Exception ( throwDyn )
33 VARID { L _ (ITvarid $$) }
34 CONID { L _ (ITconid $$) }
35 STRING { L _ (ITstring $$) }
36 INT { L _ (ITinteger $$) }
38 %monad { P } { >>= } { return }
39 %lexer { lexer } { L _ ITeof }
41 %tokentype { Located Token }
44 pkgconf :: { [ PackageConfig ] }
46 | '[' pkgs ']' { reverse $2 }
48 pkgs :: { [ PackageConfig ] }
50 | pkgs ',' pkg { $3 : $1 }
52 pkg :: { PackageConfig }
53 : CONID '{' fields '}' { $3 defaultPackageConfig }
55 fields :: { PackageConfig -> PackageConfig }
56 : field { \p -> $1 p }
57 | fields ',' field { \p -> $1 ($3 p) }
59 field :: { PackageConfig -> PackageConfig }
61 {% case unpackFS $1 of
62 "package" -> return (\p -> p{package = $3})
66 | VARID '=' STRING { id }
67 -- we aren't interested in the string fields, they're all
68 -- boring (copyright, maintainer etc.)
71 {% case unpackFS $1 of {
74 "True" -> return (\p -> p{exposed=True});
75 "False" -> return (\p -> p{exposed=False});
77 "license" -> return id; -- not interested
81 | VARID '=' CONID STRING { id }
82 -- another case of license
85 {\p -> case unpackFS $1 of
86 "exposedModules" -> p{exposedModules = $3}
87 "hiddenModules" -> p{hiddenModules = $3}
88 "importDirs" -> p{importDirs = $3}
89 "libraryDirs" -> p{libraryDirs = $3}
90 "hsLibraries" -> p{hsLibraries = $3}
91 "extraLibraries" -> p{extraLibraries = $3}
92 "extraGHCiLibraries"-> p{extraGHCiLibraries= $3}
93 "includeDirs" -> p{includeDirs = $3}
94 "includes" -> p{includes = $3}
95 "hugsOptions" -> p{hugsOptions = $3}
96 "ccOptions" -> p{ccOptions = $3}
97 "ldOptions" -> p{ldOptions = $3}
98 "frameworkDirs" -> p{frameworkDirs = $3}
99 "frameworks" -> p{frameworks = $3}
100 "haddockInterfaces" -> p{haddockInterfaces = $3}
101 "haddockHTMLs" -> p{haddockHTMLs = $3}
102 "depends" -> p{depends = []}
103 -- empty list only, non-empty handled below
107 | VARID '=' pkgidlist
108 {% case unpackFS $1 of
109 "depends" -> return (\p -> p{depends = $3})
113 pkgid :: { PackageIdentifier }
114 : CONID '{' VARID '=' STRING ',' VARID '=' version '}'
115 { PackageIdentifier{ pkgName = unpackFS $5,
118 version :: { Version }
119 : CONID '{' VARID '=' intlist ',' VARID '=' strlist '}'
120 { Version{ versionBranch=$5, versionTags=$9 } }
122 pkgidlist :: { [PackageIdentifier] }
123 : '[' pkgids ']' { $2 }
124 -- empty list case is covered by strlist, to avoid conflicts
126 pkgids :: { [PackageIdentifier] }
128 | pkgid ',' pkgids { $1 : $3 }
132 | '[' ints ']' { $2 }
135 : INT { [ fromIntegral $1 ] }
136 | INT ',' ints { fromIntegral $1 : $3 }
138 strlist :: { [String] }
140 | '[' strs ']' { $2 }
143 : STRING { [ unpackFS $1 ] }
144 | STRING ',' strs { unpackFS $1 : $3 }
148 happyError = srcParseFail
150 loadPackageConfig :: FilePath -> IO [PackageConfig]
151 loadPackageConfig conf_filename = do
152 buf <- hGetStringBuffer conf_filename
153 let loc = mkSrcLoc (mkFastString conf_filename) 1 0
154 case unP parse (mkPState buf loc defaultDynFlags) of
156 throwDyn (InstallationError (showSDoc (mkLocMessage span err)))
158 POk _ pkg_details -> do