mmikeww / AHK-v2-script-converter

AHK v1 -> v2 script converter
https://autohotkey.com/boards/viewtopic.php?f=6&t=25100
The Unlicense
519 stars 40 forks source link

Better handling of removed directives? #239

Closed Banaanae closed 1 month ago

Banaanae commented 1 month ago

V1:

#CommentFlag NewString
#EscapeChar _

MsgBox, This is a test NewString should be omitted
MsgBox % "This is a _nnewline"

V2 (Converted):

; REMOVED: #CommentFlag NewString
; REMOVED: #EscapeChar _

MsgBox("This is a test NewString should be omitted")
MsgBox("This is a _nnewline")

V2 (Expected):

; REMOVED: #CommentFlag NewString
; REMOVED: #EscapeChar _

MsgBox("This is a test") ; should be omitted
MsgBox("This is a `nnewline")
Banaanae commented 1 month ago

Currently working on this

Updated test:

#CommentFlag NewString
#EscapeChar _
#DerefChar #
#Delimiter /

Var = String

MsgBox/ This is a test NewString should be omitted
MsgBox # "This is a _nnewline"
MsgBox/ #Var#
andymbody commented 1 month ago

Not sure whether you have tried this yet, but... Can you just make a new function to search for 'NewString' and replace any occurrences found with a semicolon, then place a call to that new function in the Before_LineConverts() function at top of ConvertFuncs.ahk ? That should be a simple approach. Rather than trying to do this from _convertLines loop? Put that function call at top of Before_LineConverts() function, cause it should (probably) be done prior to any other call there. This way, all other calls that come after it will have code that has the normal semi colon and should convert normally from there.

Like this...

Before_LineConverts(&code)
{
   ;####  Please place CALLS TO YOUR FUNCTIONS here - not boilerplate code  #####

   ; must be initialized prior to entering _convertLines()
   global gUseMasking := 1  ; 2024-06-26 - set to 0 to test without masking applied

   ; replace comment tag with semi-colon
   changeCommentChar(&code)    ; changes any user-defined comment char/string to semicolon

.............

all the other calls...

    return   ; code by reference
}
Banaanae commented 1 month ago

How would it handle something like this?

MsgBox, Test
#Delimiter -
MsgBox- Test
#Delimiter /
MsgBox/ Test

Current PR handles this

andymbody commented 1 month ago

Current PR handles this

Gotcha... nice job :)

I hadn't noticed that you had already posted a PR for this prior to my comment. I noticed the PR afterwards, but didn't look too closely at that time (was distracted by some things at the moment).

Btw... I found a bug in the masking. When I fixed it, it cause one of the onMessage tests to fail. Will be submitting a fix for that soon. I mention it because (similar to this) I think you warned me about the potential of breaking certain conversions when I first suggested masking. I hadn't run into any till now. Luckily there is only one (so far)... lol.

Banaanae commented 1 month ago

When I fixed it, it cause one of the onMessage tests to fail.

Could it be failing because it's masking my mask? OnMessage conversion is very finicky :)

Luckily there is only one (so far)... lol.

If it has already lasted this long without too many major issues I doubt itll cause any now

andymbody commented 1 month ago

Could it be failing because it's masking my mask? OnMessage conversion is very finicky :)

Lol... It is the one you masked, but my mask causes your code not to see the function, since it becomes a tag instead. I made a mistake in one of my edits that caused the masking not to return the masked version of code, so all was left exposed as normal code when it made it to _convertLines(). Without masking many more are broken than just the one, so will need to make an adjustment so all work correctly with masking turned on. I haven't had power for 4 days, and it might be another 2 weeks until I do. So, progress might be delayed.

Update... I tracked the conflict between masking and onMessage to the global declaration of gmOnMessageMap... it was being declared after the masking rather than before it which reset the values it had during masking call. So I moved it and all other global declarations out of _convertLines() into their own dedicated function so they can be initialized prior to any other code (including masking). Will be submitting the fix soon.