Generate the bit in the user guide where we say what -fglasgow-exts does
[ghc-hetmet.git] / utils / mkUserGuidePart / Main.hs
1
2 module Main (main) where
3
4 import DynFlags
5
6 import Data.List
7 import System.Environment
8
9 main :: IO ()
10 main = do args <- getArgs
11           case args of
12               [] -> error "Need to give filename to generate as an argument"
13               [f] ->
14                   case f of
15                       "docs/users_guide/what_glasgow_exts_does.gen.xml" ->
16                           writeFile f whatGlasgowExtsDoes
17                       _ ->
18                           error ("Don't know what to do for " ++ show f)
19               _ -> error "Bad args"
20
21 whatGlasgowExtsDoes :: String
22 whatGlasgowExtsDoes = case maybeInitLast glasgowExtsFlags of
23                       Just (xs, x) ->
24                           let xs' = map mkInitLine xs
25                               x' = mkLastLine x
26                           in unlines (xs' ++ [x'])
27                       Nothing ->
28                           error "glasgowExtsFlags is empty?"
29     where mkInitLine = mkLine ','
30           mkLastLine = mkLine '.'
31           mkLine c f = case stripPrefix "Opt_" (show f) of
32                        Just ext -> "<option>-X" ++ ext ++ "</option>" ++ [c]
33                        Nothing -> error ("Can't parse extension: " ++ show f)
34
35 maybeInitLast :: [a] -> Maybe ([a], a)
36 maybeInitLast xs = case reverse xs of
37                    (y : ys) -> Just (reverse ys, y)
38                    _        -> Nothing
39