-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.sh
executable file
·123 lines (107 loc) · 2.92 KB
/
build.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
123
#!/usr/bin/env bash
set -euo pipefail
TMPD="$(mktemp -d --suffix vimgauche)"
readonly TMPD
cleanup() { rm -rf "$TMPD"; }
trap cleanup ERR SIGTERM EXIT
readonly LIB="$TMPD/lib.awk"
main() {
if [[ -z "${GAUCHE_SRC+defined}" ]]; then
echo "Please set GAUCHE_SRC to gauche source path" >&2
exit 1
fi
if [[ -z "${1+defined}" ]]; then
usage
fi
local cmd
case "$1" in
(cise)
cmd="$1"
shift
build_"$cmd" "$@"
;;
(*)
usage
;;
esac
}
usage() {
cat >&2 <<EOF
Usage: $0 CMD [ARG...]
Commands:
cise
EOF
exit 1
}
build_cise() {
if [[ -z "${1+defined}" ]]; then
cat >&2 <<EOF
Usage: $0 cise TSV
Generate vim syntax for Gauche CiSE statements, expressions, types, and stub forms.
Args:
TSV TSV file generated by $0 tsv
EOF
exit 1
fi
gawk -F'\t' '$3 ~ /^{cise type}$/ { print $4 }' "$1" \
| sort | uniq \
| gawk '{ switch ($0) {
default:
print "syn keyword r7rsCiSEType", $0
break
}
}'
gawk -F'\t' '$3 ~ /^{cise statement}$/ || $3 ~ /^{stub form}$/ { print $4 }' "$1" \
| sort | uniq \
| find_undefined_keywords_in 'r7rs\w*SyntaxM?' \
| gawk '{ switch ($0) {
case /(define|decl)/:
# Use special color
print "syn keyword r7rsCiSESyntaxM", $0
break
# != contains ! but not mutator
case /!$/:
# Use special color
print "syn keyword r7rsCiSESyntaxM", $0
break
default:
print "syn keyword r7rsCiSESyntax", $0
break
}
}'
gawk -F'\t' '$3 ~ /^{cise expression}$/ { print $4 }' "$1" \
| sort | uniq \
| find_undefined_keywords_in 'r7rs(\w*Syntax|Function)M?' \
| gawk '{ switch ($0) {
# != contains ! but not mutator
case /!$/:
# Use special color
print "syn keyword r7rsCiSEFunctionM", $0
break
default:
print "syn keyword r7rsCiSEFunction", $0
break
}
}'
}
find_undefined_keywords_in() {
local groupname="$1" keyword
while read -r keyword; do
if ! grep -E "syn keyword $groupname (.+ )?$(esc "$keyword")( |$)" \
./syntax/{r7rs,r7rs-large,srfi}.vim > /dev/null 2>&1
then
echo "$keyword"
fi
done
}
# Escape meta characters in EXTENDED regular expressions
esc() {
echo "$1" | sed -E 's@(\*|\.|\^|\$|\+|\?)@\\\1@g'
}
cat > "$LIB" <<'EOF'
BEGIN {
FS = "\t"
OFS = "\t"
}
EOF
main "$@"