summaryrefslogtreecommitdiff
path: root/templates
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
add data definition edsl
Diffstat (limited to 'templates')
-rw-r--r--templates/data.hs.ede27
-rw-r--r--templates/data.purs.ede16
-rw-r--r--templates/decode.hs.ede26
-rw-r--r--templates/decode.purs.ede19
-rw-r--r--templates/encode.hs.ede26
-rw-r--r--templates/encode.purs.ede15
6 files changed, 129 insertions, 0 deletions
diff --git a/templates/data.hs.ede b/templates/data.hs.ede
new file mode 100644
index 0000000..b2ad9de
--- /dev/null
+++ b/templates/data.hs.ede
@@ -0,0 +1,27 @@
1-- generated file, do not modify!
2-- {{ dateTime }}
3
4module {{ moduleName }} where
5
6import Data.Int
7import Data.Word
8import Data.Map
9import Linear
10
11{% for t in dataAndType %}
12{% case t.value | constType %}
13{% when "DataDef" %}
14data {{ t.value.dataName }}{% for c in t.value.constructors %}
15{% if c.value.fields | hasFieldNames %}
16 {% if c.first %}={% else %}|{% endif %} {{ c.value.name }}
17{% for f in c.value.fields %}{% if f.first %} { {%else%} , {%endif%}{{ f.value.fieldName }} :: {{ f.value.fieldType | hsType }}
18{% endfor %}
19 }
20{% else %}
21 {% if c.first %}={% else %}|{% endif %} {{ c.value.name }}{% for f in c.value.fields %} {{ f.value.fieldType | hsType | parens }}{% endfor %}{% endif %}{% endfor %}
22 deriving (Show, Eq, Ord)
23{% when "TypeAlias" %}
24type {{ t.value.aliasName }} = {{ t.value.aliasType | hsType }}
25{% endcase %}
26
27{% endfor %}
diff --git a/templates/data.purs.ede b/templates/data.purs.ede
new file mode 100644
index 0000000..ccaa7de
--- /dev/null
+++ b/templates/data.purs.ede
@@ -0,0 +1,16 @@
1-- generated file, do not modify!
2-- {{ dateTime }}
3
4module {{ moduleName }} where
5
6{% for t in definitions %}
7data {{ t.value.dataName }}{% for c in t.value.constructors %}
8{% if c.value.fields | hasFieldNames %}
9 {% if c.first %}={% else %}|{% endif %} {{ c.value.name }}
10{% for f in c.value.fields %}{% if f.first %} { {%else%} , {%endif%}{{ f.value.fieldName }} :: {{ f.value.fieldType | psType }}
11{% endfor %}
12 }
13{% else %}
14 {% if c.first %}={% else %}|{% endif %} {{ c.value.name }}{% for f in c.value.fields %} {{ f.value.fieldType | psType | parens }}{% endfor %}{% endif %}{% endfor %}
15
16{% endfor %}
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
diff --git a/templates/decode.purs.ede b/templates/decode.purs.ede
new file mode 100644
index 0000000..d5390a9
--- /dev/null
+++ b/templates/decode.purs.ede
@@ -0,0 +1,19 @@
1-- generated file, do not modify!
2-- {{ dateTime }}
3
4module {{ moduleName }}Decode where
5
6{% for t in definitions %}
7instance decodeJson{{ t.value.dataName }} :: DecodeJson {{ t.value.dataName }} where
8 decodeJson json = do
9 obj <- decodeJson json
10 tag <- obj .? "tag"
11 case tag of{% for c in t.value.constructors %}{% if c.value.fields | hasFieldNames %}
12 "{{ c.value.name }}" -> do{% for f in c.value.fields %}
13 {{ f.value.fieldName }} <- obj .? "{{ f.value.fieldName }}"{% endfor %}
14 pure $ {{ c.value.name }}{% for f in c.value.fields %}
15 {% if f.first %}{ {% else %}, {%endif%}{{ f.value.fieldName }}:{{ f.value.fieldName }}{% endfor %}
16 } {% else %}
17 "{{ c.value.name }}" -> {{ c.value.name }}{% for f in c.value.fields %} {% if f.first %}<$>{% else %}<*>{% endif %} obj .? "arg{{ f.index0 }}"{% endfor %}{% endif %}{% endfor %}
18
19{% endfor %} \ No newline at end of file
diff --git a/templates/encode.hs.ede b/templates/encode.hs.ede
new file mode 100644
index 0000000..f305eb1
--- /dev/null
+++ b/templates/encode.hs.ede
@@ -0,0 +1,26 @@
1-- generated file, do not modify!
2-- {{ dateTime }}
3
4{-# LANGUAGE OverloadedStrings, RecordWildCards #-}
5module {{ moduleName }}Encode where
6
7import Data.Text
8import Data.Aeson hiding (Value,Bool)
9import Data.Aeson.Types hiding (Value,Bool)
10import Linear
11
12import {{ moduleName }}
13
14(.-) :: Text -> Text -> Pair
15a .- b = a .= b
16
17{% for t in definitions %}
18instance ToJSON {{ t.value.dataName }} where
19 toJSON v = case v of{% for c in t.value.constructors %}{% if c.value.fields | hasFieldNames %}
20 {{ c.value.name }}{..} -> object
21 [ "tag" .- "{{ c.value.name }}"{% for f in c.value.fields %}
22 , "{{ f.value.fieldName }}" .= {{ f.value.fieldName }}{% endfor %}
23 ]{% else %}
24 {{ 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 %}
25
26{% endfor %} \ No newline at end of file
diff --git a/templates/encode.purs.ede b/templates/encode.purs.ede
new file mode 100644
index 0000000..e2cfcac
--- /dev/null
+++ b/templates/encode.purs.ede
@@ -0,0 +1,15 @@
1-- generated file, do not modify!
2-- {{ dateTime }}
3
4module {{ moduleName }}Encode where
5
6{% for t in definitions %}
7instance encodeJson{{ t.value.dataName }} :: EncodeJson {{ t.value.dataName }} where
8 encodeJson v = case v of{% for c in t.value.constructors %}{% if c.value.fields | hasFieldNames %}
9 {{ c.value.name }} r ->
10 "tag" := "{{ c.value.name }}" ~>{% for f in c.value.fields %}
11 "{{ f.value.fieldName }}" := r.{{ f.value.fieldName }} ~>{% endfor %}
12 jsonEmptyObject{% else %}
13 {{ c.value.name }}{% for f in c.value.fields %} arg{{ f.index0 }}{% endfor %} -> "tag" := "{{ c.value.name }}"{% for f in c.value.fields %} ~> "arg{{ f.index0 }}" := arg{{ f.index0 }}{% endfor %} ~> jsonEmptyObject{% endif %}{% endfor %}
14
15{% endfor %} \ No newline at end of file