diff options
Diffstat (limited to 'templates/data.hs.ede')
-rw-r--r-- | templates/data.hs.ede | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/templates/data.hs.ede b/templates/data.hs.ede index fccd7dc..54a148b 100644 --- a/templates/data.hs.ede +++ b/templates/data.hs.ede | |||
@@ -15,6 +15,10 @@ import Data.Aeson hiding (Value,Bool) | |||
15 | import Data.Aeson.Types hiding (Value,Bool) | 15 | import Data.Aeson.Types hiding (Value,Bool) |
16 | import Control.Monad | 16 | import Control.Monad |
17 | 17 | ||
18 | {% for m in imports %} | ||
19 | import {{ m.value }} | ||
20 | {% endfor %} | ||
21 | |||
18 | {% for t in dataAndType %} | 22 | {% for t in dataAndType %} |
19 | {% case t.value | constType %} | 23 | {% case t.value | constType %} |
20 | {% when "DataDef" %} | 24 | {% when "DataDef" %} |
@@ -33,17 +37,14 @@ type {{ t.value.aliasName }} = {{ t.value.aliasType | hsType }} | |||
33 | 37 | ||
34 | {% endfor %} | 38 | {% endfor %} |
35 | 39 | ||
36 | (.-) :: Text -> Text -> Pair | ||
37 | a .- b = a .= b | ||
38 | |||
39 | {% for t in definitions %} | 40 | {% for t in definitions %} |
40 | instance ToJSON {{ t.value.dataName }} where | 41 | instance ToJSON {{ t.value.dataName }} where |
41 | toJSON v = case v of{% for c in t.value.constructors %}{% if c.value.fields | hasFieldNames %} | 42 | toJSON v = case v of{% for c in t.value.constructors %}{% if c.value.fields | hasFieldNames %} |
42 | {{ c.value.name }}{..} -> object | 43 | {{ c.value.name }}{..} -> object |
43 | [ "tag" .- "{{ c.value.name }}"{% for f in c.value.fields %} | 44 | [ "tag" .= ("{{ c.value.name }}" :: Text){% for f in c.value.fields %} |
44 | , "{{ f.value.fieldName }}" .= {{ f.value.fieldName }}{% endfor %} | 45 | , "{{ f.value.fieldName }}" .= {{ f.value.fieldName }}{% endfor %} |
45 | ]{% else %} | 46 | ]{% else %} |
46 | {{ c.value.name }}{% for f in c.value.fields %} arg{{ f.index0 }}{% endfor %} -> object [ "tag" .- "{{ c.value.name }}"{% for f in c.value.fields %}, "arg{{ f.index0 }}" .= arg{{ f.index0 }}{% endfor %}]{% endif %}{% endfor %} | 47 | {{ c.value.name }}{% for f in c.value.fields %} arg{{ f.index0 }}{% endfor %} -> object [ "tag" .= ("{{ c.value.name }}" :: Text){% for f in c.value.fields %}, "arg{{ f.index0 }}" .= arg{{ f.index0 }}{% endfor %}]{% endif %}{% endfor %} |
47 | 48 | ||
48 | instance FromJSON {{ t.value.dataName }} where | 49 | instance FromJSON {{ t.value.dataName }} where |
49 | parseJSON (Object obj) = do | 50 | parseJSON (Object obj) = do |