summaryrefslogtreecommitdiff
path: root/templates/data.swift.ede
blob: d10c865bb147229d47842919ee231e6d24d3415e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// generated file, do not modify!
// {{ dateTime }}

enum Maybe<T> {
  case Nothing
  case Just(T)
}

{% for t in dataAndType %}
{% case t.value | constType %}
{% when "DataDef" %}
enum {{ t.value.dataName }} {
{% for c in t.value.constructors %}
{% if c.value.fields | hasFieldNames %}
  case {{ c.value.name }}({{ c.value.name }}_Data)
    struct {{ c.value.name }}_Data {
{% for f in c.value.fields %}
      var {{ f.value.fieldName }} : {{ f.value.fieldType | swiftType }}
{% endfor %}
    }
{% else %}
  case {{ c.value.name }}{% if !(c.value.fields | empty) %}({% for f in c.value.fields %}{{ f.value.fieldType | swiftType }}{% if !f.last %},{% endif %}{% endfor %}){% endif %}
{% endif %}
{% endfor %}
}
{% when "TypeAlias" %}
typealias {{ t.value.aliasName }} = {{ t.value.aliasType | swiftType }}
{% endcase %}

{% endfor %}
{#
protocol ToJSON {
    func toJSON(item: ItemType) -> [String: AnyObject]
}
#}

extension Int {
    var toJSON : [String: AnyObject] {
        return ["":""]
    }
}
extension Int32 {
    var toJSON : [String: AnyObject] {
        return ["":""]
    }
}
extension UInt {
    var toJSON : [String: AnyObject] {
        return ["":""]
    }
}
extension UInt32 {
    var toJSON : [String: AnyObject] {
        return ["":""]
    }
}
extension Float {
    var toJSON : [String: AnyObject] {
        return ["":""]
    }
}
extension Bool {
    var toJSON : [String: AnyObject] {
        return ["":""]
    }
}
extension String {
    var toJSON : [String: AnyObject] {
        return ["":""]
    }
}
extension Array {
    var toJSON : [String: AnyObject] {
        return ["":""]
    }
}
extension Dictionary {
    var toJSON : [String: AnyObject] {
        return ["":""]
    }
}
extension Maybe {
    var toJSON : [String: AnyObject] {
        return ["":""]
    }
}



{% for t in definitions %}
extension {{ t.value.dataName }} {
  var toJSON : [String: AnyObject] {
    switch self {
{% for c in t.value.constructors %}
{% if c.value.fields | hasFieldNames %}
      case .{{ c.value.name }}(let v):
        return [ "tag" : "{{ c.value.name }}"{% for f in c.value.fields %}
               , "{{ f.value.fieldName }}" : v.{{ f.value.fieldName }}.toJSON{% endfor %}
               ]
{% else %}
      case .{{ c.value.name }}{% if !(c.value.fields | empty) %}({% for f in c.value.fields %}let arg{{ f.index0 }}{% if !f.last %}, {% endif %}{% endfor %}){% endif %}:
        return [ "tag" : "{{ c.value.name }}"{% for f in c.value.fields %}, "arg{{ f.index0 }}" : arg{{ f.index0 }}.toJSON{% endfor %}]
{% endif %}
{% endfor %}
    }
  }
}
{% endfor %}