-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgenerate_builtins_c.py
40 lines (31 loc) · 953 Bytes
/
generate_builtins_c.py
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
import os.path
SCRIPT_PATH = os.path.dirname(os.path.realpath(__file__))
BUILTINS_PATH = os.path.join(SCRIPT_PATH, "builtins.txt")
def _escape_cstr_char(char: str):
if char == "\\":
return "\\\\"
if char == "\n":
return "\\n"
if char == "\"":
return r'\"'
return char
def main():
with open(BUILTINS_PATH) as f:
builtins_lines = tuple(f.readlines())
with open(os.path.join(SCRIPT_PATH, 'libtailslide', 'builtins_txt.cc'), 'w') as f:
f.write("""#ifdef _WIN32
#pragma execution_character_set("utf-8")
#endif
namespace Tailslide {
const char *BUILTINS_TXT[] = {
""")
for line in builtins_lines:
line = line.strip()
if not line:
continue
f.write('"')
f.write("".join(_escape_cstr_char(x) for x in line))
f.write('",\n')
f.write("(char*)nullptr\n};\n}\n")
if __name__ == "__main__":
main()