-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathspec.awk
68 lines (64 loc) · 1.67 KB
/
spec.awk
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
# Add markup to <pre class="grammar"> elements.
# Include langlib source files in the document.
# Non-terminal definitions are wrapped with <dfn>
# Non-termimal references are wrapped with <abbr>
# For portability, we avoid using any GNU awk extensions
/^(<pre +)?class *= *"grammar" *>/,/^<\/pre>/ {
if (/(<pre)?[^<>]*"grammar" *>/) {
i = index($0, ">");
result = substr($0, 1, i - 1);
rest = substr($0, i);
}
else {
rest = $0
result = ""
}
for (;;) {
# Tokenize where tokens are one of
# - start-tag plus following text up to, but not including, next tag
# - end-tag
# - alphanumeric string including - with optional following :=
i = match(rest, /<[a-z]+>[^<]*|[A-Za-z0-9-]+( *:=)?|<\/[a-z]+>/)
if (i == 0) {
result = (result rest)
break
}
result = (result substr(rest, 1, i - 1))
matched = substr(rest, i, RLENGTH)
rest = substr(rest, i + RLENGTH)
if (matched ~ /^[A-Za-z]/) {
i = index(matched, " ");
if (i == 0)
i = index(matched, ":");
if (i == 0)
result = (result "<abbr>" matched "</abbr>")
else
result = (result "<dfn>" substr(matched, 1, i - 1) \
"</dfn>" substr(matched, i))
}
else
result = (result matched)
}
print result
next
}
/preview<\/h1>/ {
gsub(/preview<\/h1>/, "preview " date "</h1>")
print
next
}
/^<p *class *= *"langlib">/ {
match($0, / href *= *"/)
filename = substr($0, RSTART+RLENGTH)
closeQuote = index(filename, "\"")
filename = substr(filename, 0, closeQuote - 1)
print "<pre class=\"langlib\"><![CDATA["
while ((getline line < filename) > 0) {
if (index(line, "//") != 1) {
print line
}
}
print "]]></pre>"
next
}
{ print }