Commit d34c79b6 authored by Jose A. Lopes's avatar Jose A. Lopes
Browse files

Add Template Haskell code for constant generation

Add Template Haskell functions that generate a list in Haskell
containing all the constants to be generated in Python.  This list is
an association list mapping the constant name to its Python value,
which is stored as a string.
Signed-off-by: default avatarJose A. Lopes <>
Reviewed-by: default avatarGuido Trotter <>
parent c4d68e39
......@@ -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 \
{-| 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
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)
......@@ -32,6 +32,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
module Ganeti.THH ( declareSADT
, declareIADT
, makeJSONInstance
, deCamelCase
, genOpID
, genAllConstr
, genAllOpIDs
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment