-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathace-tags
66 lines (58 loc) · 1.48 KB
/
ace-tags
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
#!/bin/bash
# This script builds the tags for use when doing
# development on the compiler or on a user-project.
echo "$0"
tags_file="./tags"
function maybe-dir {
[[ -d $1 ]] && echo $1
}
if [ $# -eq 0 ]; then
targets=(
.
"$(maybe-dir "$(llvm-config --cppflags | xargs -n 1 echo | grep '^-I' | cut -c3-)")"
"${ACE_ROOT:-/usr/local/share/ace}"
)
else
targets=(
"$*"
)
fi
echo "targets=(${targets[*]})"
ztags=/var/tmp/ztags
rm -f "$ztags"
trap 'rm -f "$ztags"' EXIT
# shellcheck disable=SC2068
ctags -f "$tags_file" -R ${targets[@]} || exit 1
gather-ace-tags() {
keyword=$1
code=$2
allow_indent=$3
spacePlus="[[:space:]]+"
if [ -n "$allow_indent" ]; then
indent="[[:space:]]*"
else
indent=""
fi
# shellcheck disable=SC2068
for target in ${targets[@]}; do
# shellcheck disable=SC2038
find -L "$target" -regex '.*\.ace$' \
| xargs grep -ERn "^$indent$keyword$spacePlus.*" \
| sed \
-Ene \
's/^([^:]+):([^:]+):('"$indent$keyword$spacePlus"'([a-zA-Z0-9_]+).*)$/\4 \1 \/^\3$\/;" '"$code"'/p' \
>> "$ztags"
done
}
gather-ace-tags "let" "v"
gather-ace-tags "fn" "f" 1
gather-ace-tags "class" "s"
gather-ace-tags "instance" "s"
gather-ace-tags "newtype" "s"
gather-ace-tags "struct" "s"
# TODO: support data-ctors
cat "$tags_file" >> "$ztags"
sort "$ztags" > "$tags_file"
rm "$ztags"
wc -l "$tags_file"
# cat "$tags_file" | grep -Ev '^!' | awk '{ print $2 }' | xargs -n 1 dirname 2>/dev/null | sort | uniq -c | sort -rn