Skip to content

Commit

Permalink
Use "dotnet tool-name" form of calling the tool. This will access loc…
Browse files Browse the repository at this point in the history
…al (preferred) or global (but only if "dotnet-tool-name" exixts).
  • Loading branch information
kaby76 committed Aug 30, 2024
1 parent 5d94da1 commit 7eaf170
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 21 deletions.
37 changes: 25 additions & 12 deletions delete-useless-parentheses.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ EXAMPLE USAGE
cd grammars-v4/abb
$(basename $0) *.g4
cd ../java/java20
trparse *.g4 | $(basename $0)
dotnet trparse -- *.g4 | $(basename $0)
EOF
exit 0
Expand All @@ -50,43 +50,56 @@ if [ ${#files[@]} -gt 0 ]
then
if [ $test -eq 1 ]
then
trparse -l -t ANTLRv4 ${files[@]} > $temp
dotnet trparse -- -l -t ANTLRv4 ${files[@]} > $temp
else
trparse -t ANTLRv4 ${files[@]} > $temp
dotnet trparse -- -t ANTLRv4 ${files[@]} > $temp
fi
else
cat - > $temp
fi

if [ $test -eq 0 ]
then
command="trquery delete"
command="dotnet trquery -- delete "
else
command="trxgrep"
command="dotnet trxgrep -- "
fi
cat $temp | $command '
(: Find all blocks... :)
//(block[
(: except not one of these ... :)
(: do not flag "a ( b | c )* d" or with other operator :)
not(./parent::ebnf/blockSuffix and ./altList/OR) and
not(./parent::ebnf/blockSuffix and ./altList/OR)
(: do not flag "(a ( b | c )* )?" because it is not the same as the '*?'-operator. :)
not(./parent::ebnf/blockSuffix/ebnfSuffix/QUESTION and ./altList[count(./*) = 1]/alternative[count(./*) = 1]/element[count(./*) = 1]/ebnf[./block and ./blockSuffix/ebnfSuffix/*]) and
and not(./parent::ebnf/blockSuffix/ebnfSuffix/QUESTION and ./altList[count(./*) = 1]/alternative[count(./*) = 1]/element[count(./*) = 1]/ebnf[./block and ./blockSuffix/ebnfSuffix/*])
(: do not flag blocks that contain a lot of elements like "(a b c)*" :)
not(./parent::ebnf/blockSuffix and count(./altList/alternative/element) > 1) and
and not(./parent::ebnf/blockSuffix and count(./altList/alternative/element) > 1)
(: do not flag if there are alts *and* it is preceed or followed by an element,
e.g., "a (b | c d)" or "(a | b) c". :)
not(./altList/OR and ../../following-sibling::element) and
not(./altList/OR and ../../preceding-sibling::element) and
and not(./altList/OR and ../../following-sibling::element)
and not(./altList/OR and ../../preceding-sibling::element)
(: do not flag "a ( v += b )* c" or with other operator :)
not(./altList/alternative/element/labeledElement/(ASSIGN or PLUS_ASSIGN) and ./parent::ebnf/blockSuffix) and
and not(
(
(count(./altList/alternative/element/labeledElement/ASSIGN) > 0)
or
(count(./altList/alternative/element/labeledElement/PLUS_ASSIGN) > 0)
)
and (count(./parent::ebnf/blockSuffix) > 0)
)
not(./parent::labeledElement/(ASSIGN or PLUS_ASSIGN))
and not(
(
(count(./parent::labeledElement/ASSIGN) > 0)
or
(count(./parent::labeledElement/PLUS_ASSIGN) > 0)
)
)
]
|
lexerBlock[
Expand Down
18 changes: 9 additions & 9 deletions find-useless-parentheses.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ found=0
main() {
if [[ $# -gt 0 ]]
then
trparse -- -l -t ANTLRv4 $@ > o.pt
dotnet trparse -- -l -t ANTLRv4 $@ > o.pt
if [ -f o.pt ] && [ -s o.pt ]
then
compute
Expand All @@ -16,9 +16,9 @@ main() {
pushd $d > /dev/null 2>&1
if [ ! -z $(find . -maxdepth 1 -name '*.g4' -printf 1 -quit) ]
then
trparse -- -l -t ANTLRv4 *.g4 > o.pt
dotnet trparse -- -l -t ANTLRv4 *.g4 > o.pt
echo Computing useless parentheses in *.g4
trparse -- -l -t ANTLRv4 *.g4 > o.pt
dotnet trparse -- -l -t ANTLRv4 *.g4 > o.pt
if [ -f o.pt ] && [ -s o.pt ]
then
compute
Expand All @@ -31,7 +31,7 @@ main() {

compute() {
found=0
cat o.pt | trquery -- grep '
cat o.pt | dotnet trquery -- grep '
(: Find all blocks... :)
//block[
(: except not one of these ... :)
Expand Down Expand Up @@ -67,8 +67,8 @@ compute() {
(count(./parent::labeledElement/PLUS_ASSIGN) > 0)
)
)
]' | trcaret -- -H > up-output.txt
cat o.pt | trquery -- grep '
]' | dotnet trcaret -- -H > up-output.txt
cat o.pt | dotnet trquery -- grep '
(: Find all blocks... :)
//lexerBlock[
(: except not one of these ... :)
Expand All @@ -79,13 +79,13 @@ compute() {
(: not(./parent::lexerElement/ebnfSuffix and ./lexerAltList/lexerAlt/lexerElements/lexerElement/lexerAtom/characterRange) and :)
not(count(./lexerAltList/lexerAlt) > 1 and ../../../lexerCommands) and
not(./parent::labeledLexerElement/(ASSIGN or PLUS_ASSIGN))
]' | trcaret -- -H >> up-output.txt
cat o.pt | trquery -- grep '
]' | dotnet trcaret -- -H >> up-output.txt
cat o.pt | dotnet trquery -- grep '
(: Find all blockSets... :)
//blockSet[
(: except not one of these ... :)
not(./OR)
]' | trcaret -- -H >> up-output.txt
]' | dotnet trcaret -- -H >> up-output.txt
if [ -s up-output.txt ]
then
echo Found useless parentheses in grammars... 1>&2
Expand Down

0 comments on commit 7eaf170

Please sign in to comment.