types.anubis
5.38 KB
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
/*
* Created by PyramIDE.
* User: フランスのトトロ aka (David RENÉ)
* Date: 21/01/2017
* Time: 01:33
* © Calexium
*/
read generation/types_header.anubis
read generation/types_messages.anubis
read generation/graphviz/graphviz_main.anubis
read system/files.anubis
read system/string.anubis
read system/lists.anubis
read tools/streams.anubis
read tools/basis.anubis
read densaku_lib/types/ds_types.anubis
read generation/intermediate_type.anubis
type Type_File_Parts:
type_file_part(
String transmit,
List(String) intermediate,
String declaration,
String message_str
)
.
define String
concat_transmit
(
List(Type_File_Parts) _parts
)=
join("",
map((Type_File_Parts part)
|->
since part is type_file_part(transmit_str, _, _, _),
transmit_str
,
_parts
)
)
.
define List(String)
unique_intermediate
(
List(String) intermediate_types,
List(String) so_far
)=
if intermediate_types is
{
[] then so_far,
[h . t ] then unique_intermediate(t, append_once(so_far, h))
}
.
define List(String)
unique_intermediate
(
List(Type_File_Parts) _parts,
List(String) so_far
)=
if _parts is
{
[] then so_far,
[h . t] then
since h is type_file_part(_, intermediate, _, _),
unique_intermediate(intermediate, so_far)
}
.
define String
concat_intermediate
(
List(Type_File_Parts) _parts
)=
with final_list = unique_intermediate(_parts, []),
join("\n",
map((String intermediate)
|->
"public type "+intermediate+":...\n\n"+
"public define Maybe("+intermediate+")\n"+
" from_Message\n"+
" (\n"+
" Message _"+to_lower(intermediate)+"_message\n"+
" )\n"+
".\n\n"+
"public define Message\n"+
" to_Message\n"+
" (\n"+
" "+intermediate+" _"+to_lower(intermediate)+"\n"+
" ).\n"
,
final_list
)
)+"\n"
.
define String
concat_declaration
(
List(Type_File_Parts) _parts
)=
join("\n\n",
map((Type_File_Parts part)
|->
since part is type_file_part(_, _, declaration_str, _),
declaration_str
,
_parts
)
)
.
define String
concat_message
(
List(Type_File_Parts) _parts
)=
join("\n\n",
map((Type_File_Parts part)
|->
since part is type_file_part(_, _, _, message_str),
message_str
,
_parts
)
)
.
define Maybe(One)
write_type_file
(
String file_name,
String header,
List(Type_File_Parts) file_parts
)=
//with file_name = dest_dir+to_lower(name)+".anubis",
//create all necessary directories if doesn't exist.
make_directories(file_name);
if file(file_name, new) is
{
failure then println("can't create file "+file_name);failure,
success(fd) then
with strm = make_stream(fd),
write_string(strm,
header +
concat_transmit(file_parts) + "\n" +
concat_intermediate(file_parts) + "\n" +
concat_declaration(file_parts) +
concat_message(file_parts)
)
}
.
define Type_File_Parts
make_type_file
(
DS_Type ds_type, //type description
String dest_dir,
List(DS_Type) same_file_types
)
=
since ds_type is ds_type(name, generation, alternatives),
println("Generating file for type ["+name+"]");
with transmit_foreign = generate_transmit_foreign_type(ds_type, same_file_types),
with intermediate_type= get_all_intermediate_type(same_file_types),
with type_declaration = dump_DS_Type(ds_type),
with message_str =
if generation is
{
no_message then "",
message then
generate_type_message_description(ds_type) +
generate_type_to_message(ds_type) +
generate_type_from_message(ds_type)
},
type_file_part(transmit_foreign, intermediate_type, type_declaration, message_str)
.
public define One
make_all_types
(
DS_Type_File_Output_Dir out_dir,
DS_Type_File_Output_Name output_file_name,
List(DS_Type) types,
String destination_dir
)=
with final_destination_dir =
if out_dir is
{
auto then destination_dir + "types/generated/",
relative_path(path) then destination_dir + path + "/",
absolute_path(path) then path
},
if output_file_name is
{
auto then
map_forget((DS_Type type)
|->
since type is ds_type(type_name, _, ds_alts),
with file_name = final_destination_dir+to_lower(type_name)+".anubis",
println("generating type file for Type ["+type_name+"] to "+file_name);
with header = generate_header,
with file_parts = make_type_file(type, final_destination_dir, []),
write_type_file(file_name, header, [file_parts])
,
types)
name(_file_name) then
with file_name = final_destination_dir+to_lower(_file_name)+".anubis",
with header = generate_header,
with file_parts =
map((DS_Type type)
|->
since type is ds_type(type_name, _, ds_alts),
println("generating type file for Type ["+type_name+"] to "+file_name);
make_type_file(type, final_destination_dir, types)
,
types),
forget(write_type_file(file_name, header, file_parts))
}
.