densaku.anubis
3.11 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
/*
* Created by PyramIDE.
* User: フランスのトトロ aka (David RENÉ)
* Date: 26/01/2017
* Time: 00:14
* © David RENÉ
*/
read hayamiki_lib/types/hayamiki.anubis
read tools/basis.anubis
read tools/streams.anubis
read system/string.anubis
read fields.anubis
read columns.anubis
read tools/ISO-8601.anubis
define List(String)
/**
*/
_generate_densaku_type
(
List(HK_Model_Column) columns,
List(String) so_far
)=
if columns is
{
[] then reverse(so_far),
[h . t ] then
since h is hk_column(name, col_type, _, _),
_generate_densaku_type(t, [ " component("+fill(to_densaku_type(col_type), 12) + ", \"" + name +"\")". so_far])
}.
public define Maybe(One)
generate_densaku_type
(
Stream stream,
HK_Table table
)=
since table is hk_table(name, short_name, model, display),
since model is hk_model(columns, constraints, show_string),
with type_name = to_upper(name, 1), //make the first character to upper case to able to be a Anubis Type.
//generate the type of the HK_Table that contain all components
if write_string(stream,
" ds_type(\""+type_name+"\", [\n"+
" alternative(\""+name+"\", [\n"+ //head of the type declaration
join(",\n",_generate_densaku_type(columns, []))+ //all components of the type
" ])\n"+
" ]),\n") is //end of declaration
{
failure then println("can't write type "+type_name); failure,
success(_) then success(unique)
}.
public define Maybe(One)
/*
*/
generate_densaku_type
(
HK_Table table,
String dest_dir,
Bool use_densaku
)=
if use_densaku then
with file_name = dest_dir+"database/generated/densaku_type.anubis",
if file(file_name, append) is
{
failure then println("can't create file "+file_name);failure,
success(fd) then
with strm = make_stream(fd),
generate_densaku_type(strm, table)
}
else
success(unique)
.
public define One
make_densaku_header
(
String dest_dir,
Bool use_densaku
)=
if use_densaku then
with file_name = dest_dir+"database/generated/densaku_type.anubis",
if file(file_name, new) is
{
failure then unique,
success(fd) then
with strm = make_stream(fd),
forget(write_string(strm,
"/*
* Created by 早見木 (Hayamiki).
* Types & Messages generator written by フランスのトトロ aka (David RENÉ)
* Date: "+_Int_to_ISO_8601_date(now)+"
* Time: "+_Int_to_ISO_8601_time(now)+"
*
*/
read densaku_lib/types/densaku.anubis
public define List(DS_Type_File) hayamiki_types_list =
[ ds_type_file(auto, auto, [\n"))
}
else
unique
.
public define One
close_densaku_file
(
String dest_dir,
Bool use_densaku
)=
if use_densaku then
with file_name = dest_dir+"database/generated/densaku_type.anubis",
if file(file_name, append) is
{
failure then unique,
success(fd) then
with strm = make_stream(fd),
forget(write_string(strm,
" ])
]
.\n"))
}
else
unique
.