-
Notifications
You must be signed in to change notification settings - Fork 1
/
cpp-like.rhai
106 lines (88 loc) · 2.88 KB
/
cpp-like.rhai
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
fn begin(name) {
"// BEGIN " ++ name ++ NL
}
fn end(name) {
"// END " ++ name ++ NL(2)
}
"// THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT!!!" ++ NL(2);
"namespace " ++ module.name.join(".") ++ " {" ++ NL(2);
begin("INCLUDES");
for imp in module.imports {
"include <" ++ imp.path.join("/") ++ ">" ++ NL
}
end("INCLUDES");
-(NL);
begin("ENUMS");
for enum in module.enums {
"enum " ++ enum.first ++ " {";
let prefix = "";
for enum_value in enum.second.values {
let name = enum_value.first;
let enum_value = enum_value.second;
if is_some(enum_value.value) {
prefix ++ NL ++ IND ++ name ++ " = " ++ unwrap(enum_value.value);
} else {
prefix ++ NL ++ IND ++ name;
}
prefix = ","
}
NL ++ "};" ++ NL(2);
}
end("ENUMS");
-(NL);
begin("DATATYPES");
for data_type in module.data_types {
"struct " ++ data_type.first ++ " {" ++ NL;
for property in data_type.second.properties {
if property.second.is_list {
let count = property.second.count;
if is_some(count) {
let count = unwrap(count);
IND ++ property.second.type.join("::") ++ " " ++ property.first ++ "[" ++ count ++ "];" ++ NL;
} else {
IND ++ property.second.type.join("::") ++ " " ++ property.first ++ "[]" ++ ";" ++ NL;
}
} else {
IND ++ property.second.type.join("::") ++ " " ++ property.first ++ ";" ++ NL;
}
}
"};" ++ NL(2);
}
end("DATATYPES");
-(NL);
begin("SERVICES");
for service in module.services {
"class " ++ service.first ++ " {" ++ NL;
for function in service.second.functions {
if is_some(function.second.return_type) {
let return_type = unwrap(function.second.return_type);
if return_type.is_list {
prefix ++ return_type.type.join("::") ++ "[]";
} else {
IND ++ return_type.type.join("::");
}
} else {
IND ++ "void";
}
" " ++ function.first ++ "(";
let prefix = "";
for argument in function.second.arguments {
if argument.second.is_list {
let count = argument.second.count;
if is_some(count) {
let count = unwrap(count);
prefix ++ argument.second.type.join("::") ++ " " ++ argument.first ++ "[" ++ count ++ "]";
} else {
prefix ++ argument.second.type.join("::") ++ " " ++ argument.first ++ "[]";
}
} else {
prefix ++ argument.second.type.join("::") ++ " " ++ argument.first;
}
prefix = ", ";
}
") = 0;" ++ NL;
}
"};" ++ NL(2);
}
end("SERVICES");
"}" ++ NL