diff options
author | Csaba Hruska <csaba.hruska@gmail.com> | 2015-11-24 12:30:44 +0100 |
---|---|---|
committer | Csaba Hruska <csaba.hruska@gmail.com> | 2015-11-24 12:30:50 +0100 |
commit | b56039baea14e416384f741551cf0c2938e70b09 (patch) | |
tree | e7ead3ea624df4ab5525074712f6cc86f6dbc0b9 | |
parent | bd9819ee0d3300f28ac0a534efe9daac6a4f7b0a (diff) |
ddl: work on universe based swift json serializer
-rw-r--r-- | Generate.hs | 2 | ||||
-rw-r--r-- | templates/data.swift.ede | 43 |
2 files changed, 40 insertions, 5 deletions
diff --git a/Generate.hs b/Generate.hs index 4eea1dc..5f5c0d0 100644 --- a/Generate.hs +++ b/Generate.hs | |||
@@ -25,6 +25,7 @@ main = do | |||
25 | dataSwift <- eitherParseFile "templates/data.swift.ede" | 25 | dataSwift <- eitherParseFile "templates/data.swift.ede" |
26 | dataJava <- eitherParseFile "templates/data.java.ede" | 26 | dataJava <- eitherParseFile "templates/data.java.ede" |
27 | dataHpp <- eitherParseFile "templates/data.hpp.ede" | 27 | dataHpp <- eitherParseFile "templates/data.hpp.ede" |
28 | dataHpp2 <- eitherParseFile "templates/data.hpp2.ede" | ||
28 | dataCpp <- eitherParseFile "templates/data.cpp.ede" | 29 | dataCpp <- eitherParseFile "templates/data.cpp.ede" |
29 | dataCs <- eitherParseFile "templates/data.cs.ede" | 30 | dataCs <- eitherParseFile "templates/data.cs.ede" |
30 | dataHs <- eitherParseFile "templates/data.hs.ede" | 31 | dataHs <- eitherParseFile "templates/data.hs.ede" |
@@ -57,6 +58,7 @@ main = do | |||
57 | -- Purescript | 58 | -- Purescript |
58 | either error (\x -> writeFile ("out/" ++ name ++ ".purs") $ LText.unpack x) $ dataPs >>= (\t -> eitherRenderWith mylib t env) | 59 | either error (\x -> writeFile ("out/" ++ name ++ ".purs") $ LText.unpack x) $ dataPs >>= (\t -> eitherRenderWith mylib t env) |
59 | -- C++ | 60 | -- C++ |
61 | either error (\x -> writeFile ("out/" ++ name ++ "2.hpp") $ LText.unpack x) $ dataHpp2 >>= (\t -> eitherRenderWith mylib t env) | ||
60 | either error (\x -> writeFile ("out/" ++ name ++ ".hpp") $ LText.unpack x) $ dataHpp >>= (\t -> eitherRenderWith mylib t env) | 62 | either error (\x -> writeFile ("out/" ++ name ++ ".hpp") $ LText.unpack x) $ dataHpp >>= (\t -> eitherRenderWith mylib t env) |
61 | either error (\x -> writeFile ("out/" ++ name ++ ".cpp") $ LText.unpack x) $ dataCpp >>= (\t -> eitherRenderWith mylib t env) | 63 | either error (\x -> writeFile ("out/" ++ name ++ ".cpp") $ LText.unpack x) $ dataCpp >>= (\t -> eitherRenderWith mylib t env) |
62 | {- | 64 | {- |
diff --git a/templates/data.swift.ede b/templates/data.swift.ede index d10c865..f2a9039 100644 --- a/templates/data.swift.ede +++ b/templates/data.swift.ede | |||
@@ -1,11 +1,6 @@ | |||
1 | // generated file, do not modify! | 1 | // generated file, do not modify! |
2 | // {{ dateTime }} | 2 | // {{ dateTime }} |
3 | 3 | ||
4 | enum Maybe<T> { | ||
5 | case Nothing | ||
6 | case Just(T) | ||
7 | } | ||
8 | |||
9 | {% for t in dataAndType %} | 4 | {% for t in dataAndType %} |
10 | {% case t.value | constType %} | 5 | {% case t.value | constType %} |
11 | {% when "DataDef" %} | 6 | {% when "DataDef" %} |
@@ -106,3 +101,41 @@ extension {{ t.value.dataName }} { | |||
106 | } | 101 | } |
107 | } | 102 | } |
108 | {% endfor %} | 103 | {% endfor %} |
104 | |||
105 | enum Maybe<T> { | ||
106 | case Nothing | ||
107 | case Just(T) | ||
108 | } | ||
109 | |||
110 | enum Type { | ||
111 | case Int | ||
112 | case Int32 | ||
113 | case Word | ||
114 | case Word32 | ||
115 | case Float | ||
116 | case Bool | ||
117 | case String | ||
118 | case Array(Type) | ||
119 | case List(Type) | ||
120 | case Maybe(Type) | ||
121 | case Map(Type,Type) | ||
122 | {% for t in definitions %} | ||
123 | case {{ t.value.dataName }} | ||
124 | {% endfor %} | ||
125 | } | ||
126 | |||
127 | func fromJSON(type: Type, personName: String) -> Any { | ||
128 | switch type { | ||
129 | case .Int: return 0 | ||
130 | case .Int32: return 0 | ||
131 | case .Word: return 0 | ||
132 | case .Word32: return 0 | ||
133 | case .Float: return 0.0 | ||
134 | case .Bool: return false | ||
135 | case .String: return "" | ||
136 | case .Array(let a): return fromJSON(a,personName) | ||
137 | case .List(let a): return fromJSON(a,personName) | ||
138 | case .Maybe(let a): return fromJSON(a,personName) | ||
139 | } | ||
140 | return 0; | ||
141 | } \ No newline at end of file | ||