summaryrefslogtreecommitdiff
path: root/Generate.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Generate.hs')
-rw-r--r--Generate.hs25
1 files changed, 13 insertions, 12 deletions
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
4import Text.EDE.Filters 4import Text.EDE.Filters
5 5
6import Data.HashMap.Strict (HashMap) 6import Data.HashMap.Strict (HashMap)
7import qualified Data.HashMap.Strict as Map 7import qualified Data.HashMap.Strict as HashMap
8import Data.Text (Text) 8import Data.Text (Text)
9import qualified Data.Map as Map
9 10
10import Data.Time.Clock 11import Data.Time.Clock
11 12
@@ -18,17 +19,6 @@ instance Quote [Char]
18instance Unquote DataDef 19instance Unquote DataDef
19instance Unquote Type 20instance Unquote Type
20 21
21mylib :: HashMap Text Term
22mylib = Map.fromList
23 -- boolean
24 [ "hasFieldNames" @: hasFieldNames
25 , "parens" @: parens
26 , "constType" @: constType
27 , "hsType" @: hsType
28 , "psType" @: psType
29 ]
30
31
32main :: IO () 22main :: IO ()
33main = do 23main = do
34 irHs <- eitherParseFile "templates/data.hs.ede" 24 irHs <- eitherParseFile "templates/data.hs.ede"
@@ -45,6 +35,17 @@ main = do
45 , "moduleName" .= name 35 , "moduleName" .= name
46 , "dateTime" .= dt 36 , "dateTime" .= dt
47 ] 37 ]
38 aliasMap = Map.fromList [(n,t) | TypeAlias n t <- def]
39 mylib :: HashMap Text Term
40 mylib = HashMap.fromList
41 -- boolean
42 [ "hasFieldNames" @: hasFieldNames
43 , "parens" @: parens
44 , "constType" @: constType
45 , "hsType" @: hsType aliasMap
46 , "psType" @: psType aliasMap
47 ]
48
48 -- Haskell 49 -- Haskell
49 either error (\x -> writeFile ("out/" ++ name ++ ".hs") $ LText.unpack x) $ irHs >>= (\t -> eitherRenderWith mylib t env) 50 either error (\x -> writeFile ("out/" ++ name ++ ".hs") $ LText.unpack x) $ irHs >>= (\t -> eitherRenderWith mylib t env)
50 either error (\x -> writeFile ("out/" ++ name ++ "Encode.hs") $ LText.unpack x) $ irEncodeHs >>= (\t -> eitherRenderWith mylib t env) 51 either error (\x -> writeFile ("out/" ++ name ++ "Encode.hs") $ LText.unpack x) $ irEncodeHs >>= (\t -> eitherRenderWith mylib t env)