diff --git a/Makefile.am b/Makefile.am index 31123398df9b2b22f96d752366b479cbc39fefb6..4dc6a7b31262e19b155313eae6c548278b3913bd 100644 --- a/Makefile.am +++ b/Makefile.am @@ -630,6 +630,7 @@ HS_LIB_SRCS = \ src/Ganeti/Hypervisor/Xen/XmParser.hs \ src/Ganeti/Hypervisor/Xen/Types.hs \ src/Ganeti/Hash.hs \ + src/Ganeti/Hs2Py/GenConstants.hs \ src/Ganeti/Hs2Py/GenOpCodes.hs \ src/Ganeti/Hs2Py/OpDoc.hs \ src/Ganeti/JQueue.hs \ diff --git a/src/Ganeti/Hs2Py/GenConstants.hs b/src/Ganeti/Hs2Py/GenConstants.hs new file mode 100644 index 0000000000000000000000000000000000000000..085b0dc62e376c1cc5e28b46175fe38df95e5d00 --- /dev/null +++ b/src/Ganeti/Hs2Py/GenConstants.hs @@ -0,0 +1,42 @@ +{-| Template Haskell code for Haskell to Python constants. + +-} + +{- + +Copyright (C) 2013 Google Inc. + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301, USA. + +-} +{-# LANGUAGE TemplateHaskell #-} +module Ganeti.Hs2Py.GenConstants (genPyConstants) where + +import Language.Haskell.TH + +import Ganeti.THH + +genList :: Name -> [Name] -> Q [Dec] +genList name consNames = do + let cons = listE $ map (\n -> tupE [mkString n, mkPyValueEx n]) consNames + sig <- sigD name [t| [(String, String)] |] + fun <- funD name [clause [] (normalB cons) []] + return [sig, fun] + where mkString n = stringE (deCamelCase (nameBase n)) + mkPyValueEx n = [| showValue $(varE n) |] + +genPyConstants :: String -> [Name] -> Q [Dec] +genPyConstants name = genList (mkName name) diff --git a/src/Ganeti/THH.hs b/src/Ganeti/THH.hs index d312c10cbd590e441ab26ac62225e5be8dced068..f98e97cc686a072a6195d232414ab232a9cac856 100644 --- a/src/Ganeti/THH.hs +++ b/src/Ganeti/THH.hs @@ -32,6 +32,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA module Ganeti.THH ( declareSADT , declareIADT , makeJSONInstance + , deCamelCase , genOpID , genAllConstr , genAllOpIDs