2 module ParsePkgConf( loadPackageConfig ) where
4 #include "HsVersions.h"
11 import ErrUtils ( mkLocMessage )
14 import Panic ( GhcException(..) )
15 import Control.Exception ( throwDyn )
26 VARID { L _ (ITvarid $$) }
27 CONID { L _ (ITconid $$) }
28 STRING { L _ (ITstring $$) }
29 INT { L _ (ITinteger $$) }
31 %monad { P } { >>= } { return }
32 %lexer { lexer } { L _ ITeof }
34 %tokentype { Located Token }
37 pkgconf :: { [ PackageConfig ] }
39 | '[' pkgs ']' { reverse $2 }
41 pkgs :: { [ PackageConfig ] }
43 | pkgs ',' pkg { $3 : $1 }
45 pkg :: { PackageConfig }
46 : CONID '{' fields '}' { $3 defaultPackageConfig }
48 fields :: { PackageConfig -> PackageConfig }
49 : field { \p -> $1 p }
50 | fields ',' field { \p -> $1 ($3 p) }
52 field :: { PackageConfig -> PackageConfig }
54 {% case unpackFS $1 of
55 "package" -> return (\p -> p{package = $3})
59 | VARID '=' STRING { id }
60 -- we aren't interested in the string fields, they're all
61 -- boring (copyright, maintainer etc.)
64 {% case unpackFS $1 of {
67 "True" -> return (\p -> p{exposed=True});
68 "False" -> return (\p -> p{exposed=False});
70 "license" -> return id; -- not interested
74 | VARID '=' CONID STRING { id }
75 -- another case of license
78 {\p -> case unpackFS $1 of
79 "exposedModules" -> p{exposedModules = $3}
80 "hiddenModules" -> p{hiddenModules = $3}
81 "importDirs" -> p{importDirs = $3}
82 "libraryDirs" -> p{libraryDirs = $3}
83 "hsLibraries" -> p{hsLibraries = $3}
84 "extraLibraries" -> p{extraLibraries = $3}
85 "extraGHCiLibraries"-> p{extraGHCiLibraries= $3}
86 "includeDirs" -> p{includeDirs = $3}
87 "includes" -> p{includes = $3}
88 "hugsOptions" -> p{hugsOptions = $3}
89 "ccOptions" -> p{ccOptions = $3}
90 "ldOptions" -> p{ldOptions = $3}
91 "frameworkDirs" -> p{frameworkDirs = $3}
92 "frameworks" -> p{frameworks = $3}
93 "haddockInterfaces" -> p{haddockInterfaces = $3}
94 "haddockHTMLs" -> p{haddockHTMLs = $3}
95 "depends" -> p{depends = []}
96 -- empty list only, non-empty handled below
100 | VARID '=' pkgidlist
101 {% case unpackFS $1 of
102 "depends" -> return (\p -> p{depends = $3})
106 pkgid :: { PackageIdentifier }
107 : CONID '{' VARID '=' STRING ',' VARID '=' version '}'
108 { PackageIdentifier{ pkgName = unpackFS $5,
111 version :: { Version }
112 : CONID '{' VARID '=' intlist ',' VARID '=' strlist '}'
113 { Version{ versionBranch=$5, versionTags=$9 } }
115 pkgidlist :: { [PackageIdentifier] }
116 : '[' pkgids ']' { $2 }
117 -- empty list case is covered by strlist, to avoid conflicts
119 pkgids :: { [PackageIdentifier] }
121 | pkgid ',' pkgids { $1 : $3 }
125 | '[' ints ']' { $2 }
128 : INT { [ fromIntegral $1 ] }
129 | INT ',' ints { fromIntegral $1 : $3 }
131 strlist :: { [String] }
133 | '[' strs ']' { $2 }
136 : STRING { [ unpackFS $1 ] }
137 | STRING ',' strs { unpackFS $1 : $3 }
141 happyError = srcParseFail
143 loadPackageConfig :: FilePath -> IO [PackageConfig]
144 loadPackageConfig conf_filename = do
145 buf <- hGetStringBuffer conf_filename
146 let loc = mkSrcLoc (mkFastString conf_filename) 1 0
147 case unP parse (mkPState buf loc defaultDynFlags) of
149 throwDyn (InstallationError (showSDoc (mkLocMessage span err)))
151 POk _ pkg_details -> do