Revision a40db327 src/Ganeti/Hs2Py/GenConstants.hs

b/src/Ganeti/Hs2Py/GenConstants.hs
29 29

  
30 30
import Ganeti.THH
31 31

  
32
fileFromModule :: Maybe String -> String
33
fileFromModule Nothing = ""
34
fileFromModule (Just name) = "src/" ++ map dotToSlash name ++ ".hs"
35
  where dotToSlash '.' = '/'
36
        dotToSlash c = c
37

  
38
comment :: Name -> String
39
comment name =
40
  "# Generated automatically from Haskell constant '" ++ nameBase name ++
41
  "' in file '" ++ fileFromModule (nameModule name) ++ "'"
42

  
32 43
genList :: Name -> [Name] -> Q [Dec]
33 44
genList name consNames = do
34 45
  let cons = listE $ map (\n -> tupE [mkString n, mkPyValueEx n]) consNames
35 46
  sig <- sigD name [t| [(String, String)] |]
36 47
  fun <- funD name [clause [] (normalB cons) []]
37 48
  return [sig, fun]
38
  where mkString n = stringE (deCamelCase (nameBase n))
49
  where mkString n = stringE (comment n ++ "\n" ++ deCamelCase (nameBase n))
39 50
        mkPyValueEx n = [| showValue $(varE n) |]
40 51

  
41 52
genPyConstants :: String -> [Name] -> Q [Dec]

Also available in: Unified diff