Use OPTIONS rather than OPTIONS_GHC for pragmas
[ghc-hetmet.git] / compiler / main / ParsePkgConf.y
1 {
2 {-# OPTIONS -w #-}
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/CodingStyle#Warnings
7 -- for details
8
9 module ParsePkgConf( loadPackageConfig ) where
10
11 #include "HsVersions.h"
12
13 import PackageConfig
14 import Lexer
15 import DynFlags
16 import FastString
17 import StringBuffer
18 import ErrUtils  ( mkLocMessage )
19 import SrcLoc
20 import Outputable
21 import Panic     ( GhcException(..) )
22 import Control.Exception ( throwDyn )
23
24 }
25
26 %token
27  '{'            { L _ ITocurly }
28  '}'            { L _ ITccurly }
29  '['            { L _ ITobrack }
30  ']'            { L _ ITcbrack }
31  ','            { L _ ITcomma }
32  '='            { L _ ITequal }
33  VARID          { L _ (ITvarid    $$) }
34  CONID          { L _ (ITconid    $$) }
35  STRING         { L _ (ITstring   $$) }
36  INT            { L _ (ITinteger  $$) }
37
38 %monad { P } { >>= } { return }
39 %lexer { lexer } { L _ ITeof }
40 %name parse
41 %tokentype { Located Token }
42 %%
43
44 pkgconf :: { [ PackageConfig ] }
45         : '[' ']'                       { [] }
46         | '[' pkgs ']'                  { reverse $2 }
47
48 pkgs    :: { [ PackageConfig ] }
49         : pkg                           { [ $1 ] }
50         | pkgs ',' pkg                  { $3 : $1 }
51
52 pkg     :: { PackageConfig }
53         : CONID '{' fields '}'          { $3 defaultPackageConfig }
54
55 fields  :: { PackageConfig -> PackageConfig }
56         : field                         { \p -> $1 p }
57         | fields ',' field              { \p -> $1 ($3 p) }
58
59 field   :: { PackageConfig -> PackageConfig }
60         : VARID '=' pkgid
61                 {% case unpackFS $1 of
62                         "package"     -> return (\p -> p{package = $3})
63                         _other        -> happyError
64                 }
65
66         | VARID '=' STRING              { id }
67                 -- we aren't interested in the string fields, they're all
68                 -- boring (copyright, maintainer etc.)
69                         
70         | VARID '=' CONID
71                 {% case unpackFS $1 of {
72                         "exposed" -> 
73                            case unpackFS $3 of {
74                                 "True"  -> return (\p -> p{exposed=True});
75                                 "False" -> return (\p -> p{exposed=False});
76                                 _       -> happyError };
77                         "license" -> return id; -- not interested
78                         _         -> happyError }
79                 }
80
81         | VARID '=' CONID STRING        { id }
82                 -- another case of license
83
84         | VARID '=' strlist             
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
104                         other -> p
105                 }
106
107         | VARID '=' pkgidlist
108                 {% case unpackFS $1 of
109                         "depends"     -> return (\p -> p{depends = $3})
110                         _other        -> happyError
111                 }
112
113 pkgid   :: { PackageIdentifier }
114         : CONID '{' VARID '=' STRING ',' VARID '=' version '}'
115                         { PackageIdentifier{ pkgName = unpackFS $5, 
116                                              pkgVersion = $9 } }
117
118 version :: { Version }
119         : CONID '{' VARID '=' intlist ',' VARID '=' strlist '}'
120                         { Version{ versionBranch=$5, versionTags=$9 } }
121
122 pkgidlist :: { [PackageIdentifier] }
123         : '[' pkgids ']'                { $2 }
124         -- empty list case is covered by strlist, to avoid conflicts
125
126 pkgids  :: { [PackageIdentifier] }
127         : pkgid                         { [ $1 ] }
128         | pkgid ',' pkgids              { $1 : $3 }
129
130 intlist :: { [Int] }
131         : '[' ']'                       { [] }
132         | '[' ints ']'                  { $2 }
133
134 ints    :: { [Int] }
135         : INT                           { [ fromIntegral $1 ] }
136         | INT ',' ints                  { fromIntegral $1 : $3 }
137
138 strlist :: { [String] }
139         : '[' ']'                       { [] }
140         | '[' strs ']'                  { $2 }
141
142 strs    :: { [String] }
143         : STRING                        { [ unpackFS $1 ] }
144         | STRING ',' strs               { unpackFS $1 : $3 }
145
146 {
147 happyError :: P a
148 happyError = srcParseFail
149
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
155         PFailed span err -> 
156            throwDyn (InstallationError (showSDoc (mkLocMessage span err)))
157
158         POk _ pkg_details -> do
159             return pkg_details
160 }