forked from wiremod/wire
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-luacheck.sh
executable file
·122 lines (102 loc) · 3.7 KB
/
generate-luacheck.sh
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/bin/bash
set -e
base_url='http://wiki.garrysmod.com'
detag() {
printf '%s' "${1##*>}"
}
wget -o /dev/null -O - "$base_url"/navbar/ |
sed -r '
# Split up before each closing tag
s#</#\n\0#g
' |
sed -r '
# Remove navbarlink tags
s/<a class='\''navbarlink'\'' .*>//g
# Remove everything before the last tag
s/.*</</
' |
{
section=
while read -r line; do
detagged="$(detag "$line")"
case "$line" in
'<h2'*' »')
# Parse menu headers
detagged="${detagged% »}"
if printf '%s' "$detagged" | grep -v -q '^[[:alpha:]_][[:alnum:]_]*$'; then continue; fi
case "$section" in
Hooks|Libraries|Classes|Panels)
printf ' "%s",\n' "$detagged"
;;
Structures|Shaders|'Lua Reference'|'Lua Tutorials'|Global|Enumerations)
:
;;
*)
echo >&2 "unknown section '$section' for '$detagged'"
;;
esac
;;
'<a'*)
# Parse menu entries
case "$section" in
Global)
printf ' "%s",\n' "$detagged"
;;
Enumerations)
echo >&2 "Retrieving enum data for $detagged"
url="$base_url/page/Enums/$detagged" # TODO: use URL from the <a> tag
output="$(wget "$url" -o /dev/null -O -)"
if ! printf '%s' "$output" | grep -q "These enumerations do not exist in the game"; then
printf '\n --- %s\n' "$detagged"
printf '%s' "$output" | sed -rn 's/^<td> ('"$detagged"'_[^[:space:]]+|[A-Z][A-Z0-9_]{2,})$/ "\1",/p'
fi
;;
Structures|Shaders|'Lua Reference'|'Lua Tutorials'|Hooks|Libraries|Classes|Panels)
:
;;
*)
echo >&2 "unknown section '$section' for '$detagged'"
;;
esac
;;
'<h1>'*)
section="$detagged"
case "$section" in
Reference)
:
;;
*)
echo >&2 "Parsing section $section"
printf '\n -- %s\n' "$section"
;;
esac
;;
'<h2>'*)
section="$detagged"
case "$section" in
Enumerations)
echo >&2 "Parsing section $section"
printf '\n -- %s' "$section" # No newline after this, to avoid double newlines
;;
esac
;;
'</'*|'<ul'*)
# Ignore closing tags and <ul> tags
:
;;
*)
echo >&2 "Warning: Unhandled line '$line'"
esac
done
printf '\n'
} |
sed -ri '
0,/BEGIN_GENERATED_CODE/ {
/BEGIN_GENERATED_CODE/ {
r /dev/stdin
}
b
}
/END_GENERATED_CODE/,$ b
d
' .luacheckrc