Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eval replacere fails to update regex vars if gosub'd #53

Open
HanryuDR opened this issue May 24, 2022 · 4 comments
Open

eval replacere fails to update regex vars if gosub'd #53

HanryuDR opened this issue May 24, 2022 · 4 comments

Comments

@HanryuDR
Copy link
Contributor

After a gosub that sends variables so that ($1,$2,etc) are updated, if you try to replacere those regex vars will not update

debug 5

gosub tst 1 1 1
exit
tst:
var DRWordle.PruneWordBank.IterateWords.word DARJE
var DRWordle.PruneWordBank.IterateWords.Pos.index 0
eval hanVAR replacere("%DRWordle.PruneWordBank.IterateWords.word", "(\w)", "$1|")
var DRWordle.PruneWordBank.IterateWords.Pos.Loop.wordChar %hanVAR[%DRWordle.PruneWordBank.IterateWords.Pos.index]
echo **%DRWordle.PruneWordBank.IterateWords.Pos.Loop.wordChar**
return
@joemcbride
Copy link
Member

Typically there are not capture groups provided when doing a regex replace as you only care about the result of the replacement.

What is the behavior you are expecting? Are you expecting the regex vars to be populated with the "pre replace" values or the "post replace" values?

Pre replace: D A R J E
Post replace: 1| 1| 1| 1| 1|

@HanryuDR
Copy link
Contributor Author

I'd expect the first output from running this script, not the second.

debug 5
var DRWordle.PruneWordBank.IterateWords.word DARJE
var DRWordle.PruneWordBank.IterateWords.Pos.index 0
eval hanVAR replacere("%DRWordle.PruneWordBank.IterateWords.word", "(\w)", "$1|")
var DRWordle.PruneWordBank.IterateWords.Pos.Loop.wordChar %hanVAR[%DRWordle.PruneWordBank.IterateWords.Pos.index]
echo **%DRWordle.PruneWordBank.IterateWords.Pos.Loop.wordChar**

gosub tst 1 1 1
exit
tst:
var DRWordle.PruneWordBank.IterateWords.word DARJE
var DRWordle.PruneWordBank.IterateWords.Pos.index 0
eval hanVAR replacere("%DRWordle.PruneWordBank.IterateWords.word", "(\w)", "$1|")
var DRWordle.PruneWordBank.IterateWords.Pos.Loop.wordChar %hanVAR[%DRWordle.PruneWordBank.IterateWords.Pos.index]
echo **%DRWordle.PruneWordBank.IterateWords.Pos.Loop.wordChar**
return
[Starting '~/Scripts/temp.cmd' at 02:10 PM]
[temp(1)]: debug 5 (actions)
[temp(2)]: var DRWordle.PruneWordBank.IterateWords.word DARJE
[temp(3)]: var DRWordle.PruneWordBank.IterateWords.Pos.index 0
[temp(4)]: eval hanVAR replacere("DARJE", "(\w)", "$1|") = D|A|R|J|E|
[temp(5)]: var DRWordle.PruneWordBank.IterateWords.Pos.Loop.wordChar D
**D**
[temp(8)]: gosub 'tst' 1 1 1 1 1 1
[temp(10)]: passing label 'tst'
[temp(11)]: var DRWordle.PruneWordBank.IterateWords.word DARJE
[temp(12)]: var DRWordle.PruneWordBank.IterateWords.Pos.index 0
[temp(13)]: eval hanVAR replacere("DARJE", "(\w)", "1|") = 1|1|1|1|1|
[temp(14)]: var DRWordle.PruneWordBank.IterateWords.Pos.Loop.wordChar 1
**1**
[temp(16)]: returning to line 8 of temp
[temp(9)]: exit

@joemcbride
Copy link
Member

I'm guessing you would still expect other variables to be evaluated in that string?

var someOtherVar someValue
eval hanVAR replacere("%DRWordle.PruneWordBank.IterateWords.word", "(\w)", "$globalVar%someOtherVar|")

@HanryuDR
Copy link
Contributor Author

HanryuDR commented May 26, 2022

Output 1 is what I would expect for both the gosub'd case and the non-gosub'd case, yes. So it's already kinda working, just not working properly if the replacere occurs after a gosub.

debug 5
var DRWordle.PruneWordBank.IterateWords.word DARJE
put #var globalVar 1
var someOtherVar someValue
eval hanVAR replacere("%DRWordle.PruneWordBank.IterateWords.word", "(\w)", "$globalVar%someOtherVar|")
echo **%hanVAR**

gosub tst 1 1 1
exit
tst:
var DRWordle.PruneWordBank.IterateWords.word DARJE
var DRWordle.PruneWordBank.IterateWords.Pos.index 0
eval hanVAR replacere("%DRWordle.PruneWordBank.IterateWords.word", "(\w)", "$1|")
var DRWordle.PruneWordBank.IterateWords.Pos.Loop.wordChar %hanVAR[%DRWordle.PruneWordBank.IterateWords.Pos.index]
echo **%DRWordle.PruneWordBank.IterateWords.Pos.Loop.wordChar**
return
[Starting '~/Scripts/temp.cmd' at 02:19 PM]
[temp(1)]: debug 5 (actions)
[temp(2)]: var DRWordle.PruneWordBank.IterateWords.word DARJE
[temp(3)]: put #var globalVar 1
[temp(4)]: var someOtherVar someValue
[temp(5)]: eval hanVAR replacere("DARJE", "(\w)", "1someValue|") = 1someValue|1someValue|1someValue|1someValue|1someValue|
**1someValue|1someValue|1someValue|1someValue|1someValue|**
[temp(8)]: gosub 'tst' 1 1 1 1 1 1
[temp(10)]: passing label 'tst'
[temp(11)]: var DRWordle.PruneWordBank.IterateWords.word DARJE
[temp(12)]: var DRWordle.PruneWordBank.IterateWords.Pos.index 0
[temp(13)]: eval hanVAR replacere("DARJE", "(\w)", "1|") = 1|1|1|1|1|
[temp(14)]: var DRWordle.PruneWordBank.IterateWords.Pos.Loop.wordChar 1
**1**
[temp(16)]: returning to line 8 of temp
[temp(9)]: exit
[Script 'temp' completed after 0s 7ms]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants