-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcoqrefs.lua
More file actions
72 lines (53 loc) · 1.57 KB
/
coqrefs.lua
File metadata and controls
72 lines (53 loc) · 1.57 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
local coqdir = "."
local texdir = "../../lir"
local texfiles = texdir .. "/*.tex"
local resultfile = "index.md"
local auxfile = texdir .. "/main.aux"
local Refs = {}
do
local f = assert(io.open(auxfile))
for line in f:lines() do
local def, ref = string.match(line, "^\\newlabel(%b{}){{(%w+)}")
if def then
def = string.sub(def, 2, -2)
Refs[def] = ref
end
end
end
local f = assert(io.popen("grep Coqlabel " .. texfiles))
local t = f:read("*a")
f:close()
f = assert(io.open(resultfile, "w"))
f:write[[
# Index to the Coq Definitions
Follows an index of all Coq definitions (including inductive types,
lemmas, theorems, etc.) used in the text:
]]
local kind = {l = "Lemma", t = "Theorem", f = "Figure"}
for ref, file, def, t in
string.gmatch(t, "\\Coqlabel(%b{})(%b{})(%b{})(%b{})") do
local ref = string.sub(ref, 2, -2)
local file = string.sub(file, 2, -2)
local def = string.sub(def, 2, -2)
local t = kind[string.sub(t, 2, -2)]
local what
do
local f = assert(io.open(coqdir .. "/" .. file))
local t = f:read("*a")
f:close()
what = {}
for def in string.gmatch(def, "(%w+)") do
local code = string.match(t, "\n(%u%w+) " .. def .. "%W")
if code then
what[#what + 1] = string.format("%s `%s`", code, def)
else
print("-------- Undef -----", file, def)
end
end
what = table.concat(what, ", ")
end
if not Refs[ref] then print("undefined ", ref) end
f:write(string.format("- %s %s: %s in file `%s`\n",
t, Refs[ref], what, file))
end
assert(f:close())