-
Notifications
You must be signed in to change notification settings - Fork 1
/
count-pt-leaves.sh
80 lines (70 loc) · 1.6 KB
/
count-pt-leaves.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
#
while getopts 'xh' opt; do
case "$opt" in
x)
set -x
;;
?|h)
cat - <<EOF
NAME
count-lexers - count the number of lexer rules in an Antlr4 grammar
SYNOPSIS
$(basename $0) ([-x | -h])* [grammar-files]
DESCRIPTION
Finds the start rule in an Antlr4 grammar. It also tests for unusual situations
in the grammar that should be corrected.
This script must be run under Linux Bash or Windows MSYS2 Bash or Windows WSL Linux.
OPTIONS
-h
Output this help message.
-x
Execute "set -x" to debug script.
EXAMPLE USAGE
git clone https://github.com/antlr/grammars-v4.git
cd grammars-v4/abb
count-lexers *.g4
cd ../java/java20
trparse *.g4 | count-lexers
EOF
exit 0
;;
esac
done
shift $((OPTIND - 1))
files=("$@")
temp=`mktemp`
if [ ${#files[@]} -gt 0 ]
then
trparse -t ANTLRv4 ${files[@]} > $temp
else
cat - > $temp
fi
cat $temp | trxgrep ' count(//*/name()[
starts-with(.,"A") or
starts-with(.,"B") or
starts-with(.,"C") or
starts-with(.,"D") or
starts-with(.,"E") or
starts-with(.,"F") or
starts-with(.,"G") or
starts-with(.,"H") or
starts-with(.,"I") or
starts-with(.,"J") or
starts-with(.,"K") or
starts-with(.,"L") or
starts-with(.,"M") or
starts-with(.,"N") or
starts-with(.,"O") or
starts-with(.,"P") or
starts-with(.,"Q") or
starts-with(.,"R") or
starts-with(.,"S") or
starts-with(.,"T") or
starts-with(.,"U") or
starts-with(.,"V") or
starts-with(.,"W") or
starts-with(.,"X") or
starts-with(.,"Y") or
starts-with(.,"Z")
])'
rm -f $temp