diff options
author | Csaba Hruska <csaba.hruska@gmail.com> | 2015-09-10 13:14:26 +0200 |
---|---|---|
committer | Csaba Hruska <csaba.hruska@gmail.com> | 2015-09-10 13:14:26 +0200 |
commit | f3b37b12d00bb98dd08cd13acd304a5dd6046ec5 (patch) | |
tree | 5e0d254593765cc219bec269371b563524835085 /Generate.hs | |
parent | ee3343a56fc02b6bd2eec93b4c839f08f7ef9a25 (diff) |
fix purescript data codegen
Diffstat (limited to 'Generate.hs')
-rw-r--r-- | Generate.hs | 25 |
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 | |||
4 | import Text.EDE.Filters | 4 | import Text.EDE.Filters |
5 | 5 | ||
6 | import Data.HashMap.Strict (HashMap) | 6 | import Data.HashMap.Strict (HashMap) |
7 | import qualified Data.HashMap.Strict as Map | 7 | import qualified Data.HashMap.Strict as HashMap |
8 | import Data.Text (Text) | 8 | import Data.Text (Text) |
9 | import qualified Data.Map as Map | ||
9 | 10 | ||
10 | import Data.Time.Clock | 11 | import Data.Time.Clock |
11 | 12 | ||
@@ -18,17 +19,6 @@ instance Quote [Char] | |||
18 | instance Unquote DataDef | 19 | instance Unquote DataDef |
19 | instance Unquote Type | 20 | instance Unquote Type |
20 | 21 | ||
21 | mylib :: HashMap Text Term | ||
22 | mylib = Map.fromList | ||
23 | -- boolean | ||
24 | [ "hasFieldNames" @: hasFieldNames | ||
25 | , "parens" @: parens | ||
26 | , "constType" @: constType | ||
27 | , "hsType" @: hsType | ||
28 | , "psType" @: psType | ||
29 | ] | ||
30 | |||
31 | |||
32 | main :: IO () | 22 | main :: IO () |
33 | main = do | 23 | main = 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) |