improve function inclusion
coderofsalvation opened this issue · 1 comments
coderofsalvation commented
Hm it seems we can still improve a bit. For example test/for.pow now seems to include the on-function because of a 'one'-string :
set -e # halt on error
set +m #
SHELL="$(echo $0)" # shellname
SHELLNAME="$(basename $SHELL)" # shellname without path
shopt -s lastpipe # flexible while loops (maintain scope)
shopt -s extglob # regular expressions
path="$(pwd)"
selfpath="$( dirname "$(readlink -f "$0")" )"
tmpfile="/tmp/$(basename $0).tmp.$(whoami)"
#
# generated by powscript (https://github.com/coderofsalvation/powscript)
#
on ()
{
func="$1";
shift;
for sig in "$@";
do
trap "$func $sig" "$sig";
done
}
declare -A foo
foo['one']="foo"
foo['two']="bar"
for k in "${!$foo[@]}"; do
v="${$foo[$k]}"
echo "$k"
echo "$v"
done
# wait for all async child processes (because "await ... then" is used in powscript)
[[ $ASYNC == 1 ]] && wait
# cleanup tmp files
if ls /tmp/$(basename $0).tmp.sqz* &>/dev/null; then
for f in /tmp/$(basename $0).tmp.sqz*; do rm $f; done
fi
exit 0
fcard commented
I think I fixed it? Here's the diff:
diff --git a/powscript b/powscript
index 0983d68..b857f47 100755
--- a/powscript
+++ b/powscript
@@ -423,7 +427,8 @@ transpile_functions(){
local odel="\\\($anydel" # open delimiters
local cdel="\\\)$anydel" # close delimiters
local nodel="[^\\\(\\\)$anydel]"
- local regex="[$odel]?$allfuncs[$cdel]?"
+ local regex="[$odel]?(?<![\d-])$allfuncs(?=![\d-])[$cdel]?"
while IFS="" read -r line; do
matched_funcs="$(echo "$line" | grep -oP "$regex" | grep -oP "($nodel)+" || printf '')"
for func in $matched_funcs; do
diff --git a/src/powscript.bash b/src/powscript.bash
index d6bd83a..12b992a 100755
--- a/src/powscript.bash
+++ b/src/powscript.bash
@@ -108,7 +108,7 @@ transpile_functions(){
local odel="\\\($anydel" # open delimiters
local cdel="\\\)$anydel" # close delimiters
local nodel="[^\\\(\\\)$anydel]"
- local regex="[$odel]?$allfuncs[$cdel]?"
+ local regex="[$odel]?(?<![\d-])$allfuncs(?=![\d-])[$cdel]?"
while IFS="" read -r line; do
matched_funcs="$(echo "$line" | grep -oP "$regex" | grep -oP "($nodel)+" || printf '')"
for func in $matched_funcs; doBut I will examine it better later.
There seems to be a new test failure in async.pow, but I don't think that's related to this.
Edit: The above is wrong, I confused \d with javascript's \w, and even then I don't think that works the same in grep. Fixed in the actual PR. (#15)