-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
129 lines (104 loc) · 5.49 KB
/
Copy pathProgram.cs
File metadata and controls
129 lines (104 loc) · 5.49 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
using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;
using System.Xml.Serialization;
namespace AutoDoxyBrane
{
class Program
{
static void Main(string[] args)
{
string projectName = "Your API";
string projectDesc = "Your API for autocompletion";
string shortcode = "yourapi";
string rootClass = "rootClass";
string rootLibName = "YourAPI";
string dir = "T:\\trunk\\documentation\\scripting\\xml";
string output = "T:\\trunk\\documentation\\scripting\\yourapi.lua";
string wrapper =
"local interpreter = {\r\n name = \"%projname%\",\r\n description = \"%projdesc%\",\r\n api = { \"baselib\", \"%shortcode%\" },\r\n fattachdebug = function(self) DebuggerAttachDefault() end,\r\n skipcompile = true,\r\n}\r\n\r\nlocal api = %APIDEFINITION%\r\n\r\n\r\nreturn {\r\n name = \"%projname%\",\r\n description = \"%projdesc%\",\r\n onRegister = function(self)\r\n ide:AddAPI(\"lua\", \"%shortcode%\", api)\r\n ide:AddInterpreter(\"%shortcode%\", interpreter)\r\n end,\r\n onUnRegister = function(self)\r\n ide:RemoveAPI(\"lua\", \"%shortcode%\")\r\n ide:RemoveInterpreter(\"%shortcode%\")\r\n end,\r\n}";
var files = Directory.GetFiles(dir, "*.xml");
List<string> members = new List<string>();
foreach (var file in files)
{
string fn = Path.GetFileName(file);
if (fn.StartsWith("class_") || fn.StartsWith("struct_"))
{
XmlSerializer serializer = new XmlSerializer(typeof(Doxygen));
using (TextReader reader = new StringReader(Sanitise(File.ReadAllText(file))))
{
Doxygen result = (Doxygen)serializer.Deserialize(reader);
members.Add(GenerateTable(result, rootClass, rootLibName));
}
}
}
var contents = wrapper
.Replace("%APIDEFINITION%", "{ \n" + string.Concat(members) + "}")
.Replace("%projname%", projectName)
.Replace("%projdesc%", projectDesc)
.Replace("%shortcode%", shortcode);
File.WriteAllText(output, contents);
}
private static string Sanitise(string file)
{
Regex r = new Regex("(<ref .*\">)", RegexOptions.Compiled);
var matches = r.Matches(file);
foreach (Match match in matches)
{
file = file.Replace(match.Value, "");
}
return file.Replace("</ref>", "");
}
private static string GenerateTable(Doxygen doxy, string rootClass, string rootLibName)
{
if ((doxy.Compounddef.Kind == "class" || doxy.Compounddef.Kind == "struct") && doxy.Compounddef.Prot == "public")
{
List<string> children = new List<string>();
string name = doxy.Compounddef.Compoundname;
var sections = doxy.Compounddef.Sectiondef;
foreach (var section in sections)
{
foreach (var member in section.Memberdef)
{
if (member.Prot != "public")
continue;
if (member.Kind == "property")
{
children.Add("\n\t\t\t" + member.Name + " = { type = \"value\", valuetype=\"" + member.Type + "\"},");
}
else if (member.Kind == "variable") // consts
{
string type = member.Definition;
if (string.IsNullOrEmpty(type) || (!string.IsNullOrEmpty(member.Type) && !member.Type.Contains(" ")))
type = member.Type;
if (type.Contains(" "))
type = type.Split(' ')[1];
children.Add("\n\t\t\t" + member.Name + " = { type = \"value\", valuetype=\"" + type + "\"},");
}
else if (member.Kind == "function")
{
if (member.Name.StartsWith("operator"))
continue;
string type = member.Type;
if (type == "void")
type = "nil";
children.Add("\n\t\t\t" + member.Name + " = { type=\"function\", " +
"args =\"" + member.Argsstring + "\", " +
"returns =\"(" + type + ")\", " +
"valuetype =\"" + type + "\", " +
"},");
}
}
}
string t = "class";
if (name == rootClass)
{
t = "lib";
name = rootLibName;
}
return "\t" + name + " = {\n\t\ttype=\"" + t + "\",\n\t\tchilds= {" + string.Join("", children) + "\n\t\t}\n\t},\n";
}
return "";
}
}
}