From f3b37b12d00bb98dd08cd13acd304a5dd6046ec5 Mon Sep 17 00:00:00 2001 From: Csaba Hruska Date: Thu, 10 Sep 2015 13:14:26 +0200 Subject: fix purescript data codegen --- Generate.hs | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'Generate.hs') diff --git a/Generate.hs b/Generate.hs index d4946fb..a701b22 100644 --- a/Generate.hs +++ b/Generate.hs @@ -4,8 +4,9 @@ import Text.EDE import Text.EDE.Filters import Data.HashMap.Strict (HashMap) -import qualified Data.HashMap.Strict as Map +import qualified Data.HashMap.Strict as HashMap import Data.Text (Text) +import qualified Data.Map as Map import Data.Time.Clock @@ -18,17 +19,6 @@ instance Quote [Char] instance Unquote DataDef instance Unquote Type -mylib :: HashMap Text Term -mylib = Map.fromList - -- boolean - [ "hasFieldNames" @: hasFieldNames - , "parens" @: parens - , "constType" @: constType - , "hsType" @: hsType - , "psType" @: psType - ] - - main :: IO () main = do irHs <- eitherParseFile "templates/data.hs.ede" @@ -45,6 +35,17 @@ main = do , "moduleName" .= name , "dateTime" .= dt ] + aliasMap = Map.fromList [(n,t) | TypeAlias n t <- def] + mylib :: HashMap Text Term + mylib = HashMap.fromList + -- boolean + [ "hasFieldNames" @: hasFieldNames + , "parens" @: parens + , "constType" @: constType + , "hsType" @: hsType aliasMap + , "psType" @: psType aliasMap + ] + -- Haskell either error (\x -> writeFile ("out/" ++ name ++ ".hs") $ LText.unpack x) $ irHs >>= (\t -> eitherRenderWith mylib t env) either error (\x -> writeFile ("out/" ++ name ++ "Encode.hs") $ LText.unpack x) $ irEncodeHs >>= (\t -> eitherRenderWith mylib t env) -- cgit v1.2.3