From 0eb84389fce02804f724b86aabef5a77604ef891 Mon Sep 17 00:00:00 2001 From: Ken Domino Date: Thu, 24 Oct 2024 08:14:05 -0400 Subject: [PATCH] Make all Trash tools local. 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 --- find-bad-lexer-actions.sh | 8 +++- find-off-skip.sh | 43 +++---------------- ...mantic-predicate-non-standard-positions.sh | 24 +++++++++++ find-start.sh | 9 ++-- find-unused-lexer-symbols.sh | 16 +++---- find-unused-parser-symbols.sh | 8 ++-- strip.xq | 6 ++- 7 files changed, 59 insertions(+), 55 deletions(-) create mode 100644 find-semantic-predicate-non-standard-positions.sh diff --git a/find-bad-lexer-actions.sh b/find-bad-lexer-actions.sh index da8c659..d07de5f 100644 --- a/find-bad-lexer-actions.sh +++ b/find-bad-lexer-actions.sh @@ -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\*` @@ -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 diff --git a/find-off-skip.sh b/find-off-skip.sh index e510013..04ca69c 100644 --- a/find-off-skip.sh +++ b/find-off-skip.sh @@ -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 \ No newline at end of file +dotnet trparse -t ANTLRv4 *.g4 \ + | dotnet trxgrep ' + //lexerRuleSpec + [./lexerRuleBlock/lexerAltList/lexerAlt/lexerCommands/lexerCommand/lexerCommandName/identifier/RULE_REF/text()="skip"] + /TOKEN_REF/text()' + + diff --git a/find-semantic-predicate-non-standard-positions.sh b/find-semantic-predicate-non-standard-positions.sh new file mode 100644 index 0000000..7a2dc8d --- /dev/null +++ b/find-semantic-predicate-non-standard-positions.sh @@ -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 diff --git a/find-start.sh b/find-start.sh index 03d33a3..a230dcb 100644 --- a/find-start.sh +++ b/find-start.sh @@ -1,4 +1,5 @@ #!/usr/bin/bash +#set -x while getopts 'xv:s:g:' opt; do case "$opt" in @@ -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[@]} @@ -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[@]} @@ -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 diff --git a/find-unused-lexer-symbols.sh b/find-unused-lexer-symbols.sh index 3b07e95..2d1cc8d 100644 --- a/find-unused-lexer-symbols.sh +++ b/find-unused-lexer-symbols.sh @@ -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 @@ -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 diff --git a/find-unused-parser-symbols.sh b/find-unused-parser-symbols.sh index d96be00..111f8ff 100644 --- a/find-unused-parser-symbols.sh +++ b/find-unused-parser-symbols.sh @@ -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... @@ -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 diff --git a/strip.xq b/strip.xq index 0ed19df..c1970c5 100644 --- a/strip.xq +++ b/strip.xq @@ -1,4 +1,6 @@ delete //DOC_COMMENT; +delete //@BLOCK_COMMENT; +delete //@LINE_COMMENT; move //labeledAlt/(POUND | identifer)/@WS ./ancestor::labeledAlt; delete //labeledAlt/(POUND | identifier); @@ -13,7 +15,7 @@ delete //rulePrequel; delete //ruleReturns; delete //exceptionGroup; delete //throwsSpec; -(% delete //prequelConstruct; %) +(: delete //prequelConstruct; :) delete //elementOptions; move //actionBlock/@WS[1] ../..; @@ -21,3 +23,5 @@ delete //actionBlock/(. | ./following-sibling::QUESTION[1]); move //argActionBlock/@WS[1] ../..; delete //argActionBlock; + +delete //action_;