summaryrefslogtreecommitdiff
path: root/templates/decode.hs.ede
diff options
context:
space:
mode:
authorCsaba Hruska <csaba.hruska@gmail.com>2015-09-07 18:37:15 +0200
committerCsaba Hruska <csaba.hruska@gmail.com>2015-09-07 18:37:15 +0200
commitab758fd36fae40f3cc998065b8bf9c4ce5e8169b (patch)
treebaebb3584770c6abb64c821daa62e1769816aaaa /templates/decode.hs.ede
add data definition edsl
Diffstat (limited to 'templates/decode.hs.ede')
-rw-r--r--templates/decode.hs.ede26
1 files changed, 26 insertions, 0 deletions
diff --git a/templates/decode.hs.ede b/templates/decode.hs.ede
new file mode 100644
index 0000000..743bb39
--- /dev/null
+++ b/templates/decode.hs.ede
@@ -0,0 +1,26 @@
1-- generated file, do not modify!
2-- {{ dateTime }}
3
4{-# LANGUAGE OverloadedStrings #-}
5module {{ moduleName }}Decode where
6
7import Data.Text
8import Data.Aeson hiding (Value,Bool)
9import Control.Monad
10import Linear
11import {{ moduleName }}
12
13{% for t in definitions %}
14instance FromJSON {{ t.value.dataName }} where
15 parseJSON (Object obj) = do
16 tag <- obj .: "tag"
17 case tag :: Text of{% for c in t.value.constructors %}{% if c.value.fields | hasFieldNames %}
18 "{{ c.value.name }}" -> do{% for f in c.value.fields %}
19 {{ f.value.fieldName }} <- obj .: "{{ f.value.fieldName }}"{% endfor %}
20 pure $ {{ c.value.name }}{% for f in c.value.fields %}
21 {% if f.first %}{ {% else %}, {%endif%}{{ f.value.fieldName }} = {{ f.value.fieldName }}{% endfor %}
22 } {% else %}
23 "{{ c.value.name }}" -> {% for f in c.value.fields %}{% if f.first %}{{ c.value.name }} <$>{% else %} <*>{% endif %} obj .: "arg{{ f.index0 }}"{%else%}pure {{ c.value.name }}{% endfor %}{% endif %}{% endfor %}
24 parseJSON _ = mzero
25
26{% endfor %} \ No newline at end of file