Repository navigation
Expand file tree
/
Copy pathexport.lua
More file actions
82 lines (67 loc) · 1.93 KB
/
Copy pathexport.lua
File metadata and controls
82 lines (67 loc) · 1.93 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
local src_path, dest_path = ...
local xml = require("xml_parser").newParser()
local root = xml:ParseXmlText(io.open(src_path):read("*a"))
local file = io.open(dest_path, "w")
local indent_count = 0
local function indent(count)
indent_count = indent_count + (count or 2)
end
local function unindent(count)
indent_count = indent_count - (count or 2)
end
local function write(fmt, ...)
file:write(string.format(fmt, ...))
end
local function writel(fmt, ...)
if indent_count > 0 then
file:write(string.rep(' ', indent_count))
end
file:write(string.format(fmt, ...))
file:write('\n')
end
write('return ')
local function write_node(node, isroot)
local function node_args(args)
local str = ""
for _, v in ipairs(args:children()) do
str = str .. v["@TEXT"] .. ","
end
return str
end
local function node_vars(args)
local str = ""
for _, v in ipairs(args:children()) do
str = string.format("%s\"%s\",", str, v["@TEXT"])
end
return str
end
writel('{')
indent(2)
writel('name = [[%s]],', string.match(node["@TEXT"],"(%w+)"))
writel('desc = [[%s]],', string.match(node["@TEXT"],"%((.+)%)"))
local children = {}
for _, v in ipairs(node:children()) do
local text = v['@TEXT']
if text == "args" then
writel('args = {%s},', node_args(v))
elseif text == "input" then
writel('input = {%s},', node_vars(v))
elseif text == "output" then
writel('output = {%s},', node_vars(v))
else
children[#children + 1] = v
end
end
if #children > 0 then
writel('children = {')
indent(2)
for _, child in ipairs(children) do
write_node(child)
end
unindent(2)
writel('},')
end
unindent(2)
writel('}%s', isroot and "" or ",")
end
write_node(root.map.node, true)