-
Notifications
You must be signed in to change notification settings - Fork 2
/
doc.lua
107 lines (100 loc) · 3.03 KB
/
doc.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
-- This is an incomplete Lua Script to replace the Awk script that
-- generates the documentation.
title = "Luafann Documentation"
print("<HTML><HEAD><TITLE>" .. title .. "</TITLE>\n<STYLE>\n<!--")
print("tt,b {color:rgb(64,128,64)}")
print("pre {background:rgb(235,255,235);color:rgb(64,128,64);margin-left:30px;margin-right:30px}")
print("h2 {background:rgb(150,255,150);color:rgb(32,64,32);text-align:center}")
print("h3 {background:rgb(200,255,200);color:rgb(32,64,32);text-align:left}")
print("h4 {font-family:monospace;color:rgb(64,128,64);background:rgb(220,255,220)}")
print("body {font-family:arial, \"lucida console\", sans-serif;margin-left:20px;margin-right:20px}")
print("-->\n</STYLE>\n</HEAD><BODY>")
function filter(line)
line = string.gsub(line, "&", "&")
line = string.gsub(line, "<", "<")
line = string.gsub(line, ">", ">")
line = string.gsub(line, "\\n", "<BR>")
line = string.gsub(line, "{{", "<TT>")
line = string.gsub(line, "}}", "</TT>")
line = string.gsub(line, "{%*", "<B>")
line = string.gsub(line, "%*}", "</B>")
line = string.gsub(line, "{/", "<I>")
line = string.gsub(line, "/}", "</I>")
return line
end
for line in io.lines() do
if string.match(line, "/%*") then
incomment = true
elseif string.match(line, "%*/") then
incomment = false
end
-- Unfortunately the /****************** comments in some of my
-- source code caused problems, and this is the workaround
if incomment and string.match(line, "/%*%*%*+%s*$") then
incomment = false
end
if incomment then
-- This sillyness with the "while true" and the breaks is because I
-- just discovered to my horror that Lua does not have a "continue"
while true do
m = string.match (line, "%s*/?%*#(.*)$")
if m ~= nil then
print(filter(m))
break
end
m = string.match (line, "^%s*/?%*H(.*)")
if m ~= nil then
print("<H2>" .. filter(m) .. "</H2>")
break
end
m = string.match (line, "^%s*/?%*h(.*)")
if m ~= nil then
print("<H3>" .. filter(m) .. "</H3>")
break
end
m = string.match (line, "^%s*/?%*!(.*)")
if m ~= nil then
print("<H4><TT>" .. filter(m) .. "</TT></H4>")
break
end
m = string.match (line, "^%s*/?%*%-(.*)")
if m ~= nil then
print("<HR>" .. filter(m))
break
end
m = string.match (line, "^%s*/?%*%[(.*)")
if m ~= nil then
print("<PRE>" .. filter(m))
break
end
m = string.match (line, "^%s*/?%*%](.*)")
if m ~= nil then
print("</PRE>" .. filter(m))
break
elseif string.match (line, "^%s*/?%*{") then
print("<UL>")
break
elseif string.match (line, "^%s*/?%*}") then
print("</UL>")
break
end
m = string.match (line, "^%s*/?%*%*(.*)")
if m ~= nil then
print("<LI>" .. filter(m))
break
end
m = string.match (line, "^%s*/?%*x(.*)")
if m ~= nil then
print("<br><b>Example:</b><tt>" .. filter(m) .. "</tt>")
break
end
m = string.match (line, "^%s*/?%*n(.*)")
if m ~= nil then
print("<br><b>Note:</b><i>" .. filter(m) .. "</i><br>")
break
end
break
end
end
end
print("</BODY></HTML>")