diff options
author | Csaba Hruska <csaba.hruska@gmail.com> | 2015-09-07 18:37:15 +0200 |
---|---|---|
committer | Csaba Hruska <csaba.hruska@gmail.com> | 2015-09-07 18:37:15 +0200 |
commit | ab758fd36fae40f3cc998065b8bf9c4ce5e8169b (patch) | |
tree | baebb3584770c6abb64c821daa62e1769816aaaa /templates/decode.hs.ede |
add data definition edsl
Diffstat (limited to 'templates/decode.hs.ede')
-rw-r--r-- | templates/decode.hs.ede | 26 |
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 #-} | ||
5 | module {{ moduleName }}Decode where | ||
6 | |||
7 | import Data.Text | ||
8 | import Data.Aeson hiding (Value,Bool) | ||
9 | import Control.Monad | ||
10 | import Linear | ||
11 | import {{ moduleName }} | ||
12 | |||
13 | {% for t in definitions %} | ||
14 | instance 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 | ||