Skip to content

Commit

Permalink
Make all Trash tools local.
Browse files Browse the repository at this point in the history
Best to use local tools so repos can have different set of tool versions. https://github.com/kaby76/Trash?tab=readme-ov-file#install-locally
  • Loading branch information
kaby76 committed Oct 24, 2024
1 parent 7eaf170 commit 0eb8438
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 55 deletions.
8 changes: 6 additions & 2 deletions find-bad-lexer-actions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
if [[ $# -gt 0 ]]
then
echo Finding actions in lexer grammars that start an alt... >&2
trparse -l -t ANTLRv4 $@ 2> /dev/null | trxgrep ' //lexerElements/lexerElement[actionBlock and position() = 1]' | trcaret
dotnet trparse -l -t ANTLRv4 $@ 2> /dev/null | \
dotnet trxgrep ' //lexerElements/lexerElement[actionBlock and position() = 1]' | \
dotnet trcaret
else
echo Finding actions in lexer grammars that start an alt... >&2
for i in `find . -name desc.xml | grep -v Generated\*`
Expand All @@ -13,7 +15,9 @@ else
if [ ! -z $(find . -maxdepth 1 -name '*.g4' -printf 1 -quit) ]
then
# Parse all grammar files so that any imports can also be checked.
trparse -l -t ANTLRv4 *.g4 2> /dev/null | trxgrep ' //lexerElements/lexerElement[actionBlock and position() = 1]' | trcaret
dotnet trparse -l -t ANTLRv4 *.g4 2> /dev/null | \
dotnet trxgrep ' //lexerElements/lexerElement[actionBlock and position() = 1]' | \
dotnet trcaret
fi
popd > /dev/null 2>&1
done
Expand Down
43 changes: 7 additions & 36 deletions find-off-skip.sh
Original file line number Diff line number Diff line change
@@ -1,39 +1,10 @@
#!/usr/bin/bash
# "Setting MSYS2_ARG_CONV_EXCL so that Trash XPaths do not get mutulated."
export MSYS2_ARG_CONV_EXCL="*"
for i in `find . -name pom.xml | grep -v Generated | grep -v target`
do
base=`dirname $i`
echo $i
grep -qs . $base/*.g4
if [ "$?" = "0" ]
then
for j in "$base"/*.g4
do
echo $j | grep Parser.g4
if [ "$?" = "0" ]
then
continue
fi
echo $j >> xxx-all
fgrep "> skip" $j
if [ "$?" = "0" ]
then
echo $j >> xxx-with
fi
fgrep "> channel" $j
if [ "$?" = "0" ]
then
echo $j >> xxx-with
fi
# trparse -t antlr4 $j \
# | trxgrep -e '
# for $i in (
# //lexerRuleSpec
# [./lexerRuleBlock/lexerAltList/lexerAlt/lexerCommands/lexerCommand/lexerCommandName/identifier/RULE_REF/text()="skip"]
# /TOKEN_REF/text()])
# return concat("line ", $i/@Line, " col ", $i/@Column, " """, $i/@Text,"""")'
#
done
fi
done
dotnet trparse -t ANTLRv4 *.g4 \
| dotnet trxgrep '
//lexerRuleSpec
[./lexerRuleBlock/lexerAltList/lexerAlt/lexerCommands/lexerCommand/lexerCommandName/identifier/RULE_REF/text()="skip"]
/TOKEN_REF/text()'


24 changes: 24 additions & 0 deletions find-semantic-predicate-non-standard-positions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#
if [[ $# -gt 0 ]]
then
echo Finding actions in grammars... >&2
dotnet trparse -l -t ANTLRv4 $@ | \
dotnet trquery grep ' //actionBlock[following-sibling::QUESTION and not ./self[1] ]' | \
dotnet trcaret
else
echo Finding actions in grammars... >&2
for i in `find . -name desc.xml | grep -v Generated\*`
do
echo $i
d=`dirname $i`
pushd $d > /dev/null 2>&1
if [ ! -z $(find . -maxdepth 1 -name '*.g4' -printf 1 -quit) ]
then
# Parse all grammar files so that any imports can also be checked.
dotnet trparse -l -t ANTLRv4 *.g4 2> /dev/null | \
dotnet trxgrep ' //actionBlock[following-sibling::QUESTION]' | \
dotnet trcaret
fi
popd > /dev/null 2>&1
done
fi
9 changes: 5 additions & 4 deletions find-start.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/bash
#set -x

while getopts 'xv:s:g:' opt; do
case "$opt" in
Expand Down Expand Up @@ -43,12 +44,12 @@ files=("$@")
temp=`mktemp`
if [ ${#files[@]} -gt 0 ]
then
trparse -t ANTLRv4 ${files[@]} > $temp
dotnet trparse -- -t ANTLRv4 ${files[@]} > $temp
else
cat - > $temp
fi

count=(`cat $temp | trxgrep ' //grammarSpec/grammarDecl[not(grammarType/LEXER)]//parserRuleSpec//alternative/element[.//TOKEN_REF/text()="EOF"]/following-sibling::element' | trtext -c`)
count=(`cat $temp | dotnet trxgrep -- ' //grammarSpec/grammarDecl[not(grammarType/LEXER)]//parserRuleSpec//alternative/element[.//TOKEN_REF/text()="EOF"]/following-sibling::element' | dotnet trtext -- -c`)
if [ ${#count[@]} -gt 0 ]
then
for i in ${count[@]}
Expand All @@ -66,7 +67,7 @@ then
fi
done
fi
count=`cat $temp | trxgrep ' //grammarSpec/grammarDecl[not(grammarType/LEXER)]//labeledAlt[.//TOKEN_REF/text()="EOF" and count(../labeledAlt) > 1]' | trtext -c`
count=`cat $temp | dotnet trxgrep -- ' //grammarSpec/grammarDecl[not(grammarType/LEXER)]//labeledAlt[.//TOKEN_REF/text()="EOF" and count(../labeledAlt) > 1]' | dotnet trtext -- -c`
if [ ${#count[@]} -gt 0 ]
then
for i in ${count[@]}
Expand All @@ -84,7 +85,7 @@ then
fi
done
fi
start=(`cat $temp | trxgrep -- '
start=(`cat $temp | dotnet trxgrep -- -e '
/grammarSpec[grammarDecl[not(grammarType/LEXER)]]
//parserRuleSpec[ruleBlock//TOKEN_REF/text()="EOF"]/RULE_REF/text()' | tr -d '\r'`)
echo "Start rules:" 1>&2
Expand Down
16 changes: 8 additions & 8 deletions find-unused-lexer-symbols.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ then
cp $@ foobarfoobar
cd foobarfoobar
echo 1st pass: fold string literals in parser rules to make explicit lexer rule used.
trparse *.g4 2> /dev/null | trfoldlit | trsponge -c true 2> /dev/null
dotnet trparse -- *.g4 2> /dev/null | dotnet trfoldlit | dotnet trsponge -- -c true 2> /dev/null
echo 2nd pass: find unreferenced lexer rule symbols.
trparse *.g4 2> /dev/null | \
trxgrep ' //lexerRuleSpec[
dotnet trparse -- *.g4 2> /dev/null | \
dotnet trxgrep -- ' //lexerRuleSpec[
not(doc("*")//ruleBlock//TOKEN_REF/text() = ./TOKEN_REF/text())
and not(doc("*")//lexerRuleBlock//TOKEN_REF/text() = ./TOKEN_REF/text())
and not(./lexerRuleBlock//lexerCommands)
]/TOKEN_REF' | \
trtext
dotnet trtext
cd ..
rm -rf foobarfoobar
else
Expand All @@ -33,15 +33,15 @@ else
cp *.g4 foobarfoobar
cd foobarfoobar
echo 1st pass: fold string literals in parser rules to make explicit lexer rule used.
trparse *.g4 2> /dev/null | trfoldlit | trsponge -c true 2> /dev/null
dotnet trparse -- *.g4 2> /dev/null | dotnet trfoldlit | dotnet trsponge -- -c true 2> /dev/null
echo 2nd pass: find unreferenced lexer rule symbols.
trparse *.g4 2> /dev/null | \
trxgrep ' //lexerRuleSpec[
dotnet trparse -- *.g4 2> /dev/null | \
dotnet trxgrep -- ' //lexerRuleSpec[
not(doc("*")//ruleBlock//TOKEN_REF/text() = ./TOKEN_REF/text())
and not(doc("*")//lexerRuleBlock//TOKEN_REF/text() = ./TOKEN_REF/text())
and not(./lexerRuleBlock//lexerCommands)
]/TOKEN_REF' | \
trtext
dotnet trtext
cd ..
rm -rf foobarfoobar
popd > /dev/null 2>&1
Expand Down
8 changes: 4 additions & 4 deletions find-unused-parser-symbols.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ if [[ $# -gt 0 ]]
then
echo Arguments were provided.
echo Finding unused parser symbols in grammars...
trparse -l -t ANTLRv4 $@ 2> /dev/null | trxgrep ' //parserRuleSpec
dotnet trparse -- -l -t ANTLRv4 $@ 2> /dev/null | dotnet trquery -- grep ' //parserRuleSpec
[not(doc("*")//ruleBlock//RULE_REF/text() = ./RULE_REF/text())
and not(./ruleBlock//TOKEN_REF/text() = "EOF")]' | trcaret
and not(./ruleBlock//TOKEN_REF/text() = "EOF")]' | dotnet trcaret
else
echo No arguments were provided.
echo Finding unused parser symbols in grammars...
Expand All @@ -15,9 +15,9 @@ else
d=`dirname $i`
pushd $d > /dev/null 2>&1
# Parse all grammar files so that any imports can also be checked.
trparse -l -t ANTLRv4 *.g4 2> /dev/null | trxgrep ' //parserRuleSpec
dotnet trparse -- -l -t ANTLRv4 *.g4 2> /dev/null | dotnet trquery -- grep ' //parserRuleSpec
[not(doc("*")//ruleBlock//RULE_REF/text() = ./RULE_REF/text())
and not(./ruleBlock//TOKEN_REF/text() = "EOF")]' | trcaret
and not(./ruleBlock//TOKEN_REF/text() = "EOF")]' | dotnet trcaret
popd > /dev/null 2>&1
done
fi
Expand Down
6 changes: 5 additions & 1 deletion strip.xq
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
delete //DOC_COMMENT;
delete //@BLOCK_COMMENT;
delete //@LINE_COMMENT;

move //labeledAlt/(POUND | identifer)/@WS ./ancestor::labeledAlt;
delete //labeledAlt/(POUND | identifier);
Expand All @@ -13,11 +15,13 @@ delete //rulePrequel;
delete //ruleReturns;
delete //exceptionGroup;
delete //throwsSpec;
(% delete //prequelConstruct; %)
(: delete //prequelConstruct; :)
delete //elementOptions;

move //actionBlock/@WS[1] ../..;
delete //actionBlock/(. | ./following-sibling::QUESTION[1]);

move //argActionBlock/@WS[1] ../..;
delete //argActionBlock;

delete //action_;

0 comments on commit 0eb8438

Please sign in to comment.