This repository has been archived by the owner on Aug 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
extractor.d
96 lines (79 loc) · 3.13 KB
/
extractor.d
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
/** This file parses all scripts in the GameMaker 1.4 Library Extensions.
* Creates one file which contains all extensions in `output/gm_extensions.gml`.
* Creates reference file `reference.md`.
*/
import std.file : readText, dirEntries, SpanMode;
import std.stdio : File, write, writeln;
import std.string : replace, split;
import std.algorithm : canFind;
void main()
{
writeln("Opening file 'gm_extensions.gml'");
File output = File("output/gm_extensions.gml", "w"); output.writeln("#define gm_extensions\n///Game Maker 1.4 Library Extensions\n");
writeln("Opening file 'REFERENCE.md'");
File reference = File("REFERENCE.md", "w"); reference.writeln("# GameMaker 1.4 Library Extensions\n## Contents\n");
writeln("Loading all unittests");
string unittests = readText("scripts/_unittests.gml");
writeln("Iterating all scripts to get a full list of all the functions");
//bad, initial loop to create list of references
foreach(script; dirEntries("scripts/", "extension_*.gml", SpanMode.shallow))
{
auto fileName = script.name.split("/")[$-1];
reference.writeln("### ", fileName.split(".")[0], "\n");
writeln("Loading script ", fileName);
auto lines = readText(script.name).replace("\r\n", "\n").split("\n");
foreach(line; lines)
{
if(line.canFind("#define ") && !line.canFind("extension_"))
{
auto functionName = line[8 .. $];
if(fileName != "extension_misc.gml" && !unittests.canFind("///"~functionName))
{
writeln("WARN: ", functionName, " does not have unittests!");
}
reference.writeln("1. [", functionName, "](#", functionName, ")");
}
}
reference.writeln();
}
reference.writeln("\n## Reference\n");
foreach(script; dirEntries("scripts/", "*.gml", SpanMode.shallow))
{
//write to output file
auto lines = readText(script.name).replace("\r\n", "\n").split("\n");
foreach(line; lines)
{
if(!line.canFind("extension_"))
{
output.writeln(line);
}
}
//write to reference
if(!script.name.split("/")[$ - 1].canFind("extension_"))
{
continue;
}
auto fileName = script.name.split("/")[$-1];
reference.writeln("## ", fileName.split(".")[0], "\n");
for(int i = 0; i < lines.length; ++i)
{
if(lines[i].canFind("#define ") && !lines[i].canFind("extension_"))
{
reference.writeln("### [", lines[i][8 .. $], "](/scripts/", fileName, "#L", i+1, ")");
while(lines[++i].canFind("//"))
{
auto line = lines[i];
if(line.canFind("///"))
{
reference.writeln("\n##### ", line[3 .. $]);
}
else
{
reference.writeln(line[2 .. $], " ");
}
}
reference.writeln();
}
}
}
}