-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextract_defines.lua
89 lines (70 loc) · 1.61 KB
/
extract_defines.lua
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
local parse = require "_ParseVk"
local elements = {}
function elements:push(name)
table.insert(self, name)
end
function elements:pop(name)
assert(#self > 0)
assert(name == self[#self])
self[#self] = nil
end
function elements:index(index)
index = index or -1
if(index < 0) then
local retIx = #self + 1 + index
assert(retIx > 0)
return self[retIx]
elseif(index > 0) then
assert(index <= #self)
return self[index]
else
assert(false)
end
end
function elements:top() return self:index() end
local categories = {}
local builder = {}
local hasCat = false
local inTypedef = false
function builder.startElement(name, nsURI)
elements:push(name)
if((name == "type") and (elements:index(-2) == "types")) then
assert(inTypedef == false)
inTypedef = true
hasCat = false
end
end
function builder.closeElement(name, nsURI)
if((name == "type") and (elements:index(-2) == "types")) then
assert(inTypedef == true)
inTypedef = false
if(not hasCat) then
local count = categories[0] or 0
categories[0] = count + 1
end
end
elements:pop(name)
end
function builder.attribute(name, value, nsURI)
if(inTypedef) then
if(name == "category") then
local count = categories[value] or 0
categories[value] = count + 1
hasCat = true
end
end
end
function builder.text(text)
end
function builder.comment(content)
end
function builder.pi(target, content)
end
parse.parse(builder)
for catName, count in pairs(categories) do
if(catName == 0) then
print("<<Unknown>>", count)
else
print(catName, count)
end
end