Skip to content

Commit

Permalink
AMB Fix formatting and Multi-line regex
Browse files Browse the repository at this point in the history
Fix formatting of _SendMessage within 1Commands.ahk (that looked like a formatting issue)
Adjustment to Multi-line regex needle within MaskCode.ahk - now 4-5 times more efficient
  • Loading branch information
andymbody committed Jul 6, 2024
1 parent c5bc41f commit 18b3376
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 23 deletions.
34 changes: 19 additions & 15 deletions convert/1Commands.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -498,20 +498,24 @@ global gmAhkCmdsToConvert := OrderedMap(
return false
}

_SendMessage(p){
if (p[3] ~= "^&.*"){
p[3] := SubStr(p[3],2)
Out := format('if (type(' p[3] ')="Buffer"){ `;V1toV2 If statement may be removed depending on type parameter`n`r' gIndentation ' ErrorLevel := SendMessage({1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9})', p*)
Out := RegExReplace(Out, "[\s\,]*\)$", ")")
Out .= format('`n`r' gIndentation '} else{`n`r' gIndentation ' ErrorLevel := SendMessage({1}, {2}, StrPtr({3}), {4}, {5}, {6}, {7}, {8}, {9})', p*)
Out := RegExReplace(Out, "[\s\,]*\)$", ")")
Out .= '`n`r' gIndentation "}"
return Out
}
if (p[3] ~= "^`".*") {
p[3] := 'StrPtr(' p[3] ')'
}
_SendMessage(p) {

Out := format("ErrorLevel := SendMessage({1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9})", p*)
Return RegExReplace(Out, "[\s\,]*\)$", ")")

if (p[3] ~= "^&.*"){
p[3] := SubStr(p[3],2)
Out := format('if (type(' . p[3] . ')="Buffer"){ `;V1toV2 If statement may be removed depending on type parameter`n`r' . gIndentation
. ' ErrorLevel := SendMessage({1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9})', p*)
Out := RegExReplace(Out, "[\s\,]*\)$", ")")
Out .= format('`n`r' . gIndentation . '} else{`n`r' . gIndentation
. ' ErrorLevel := SendMessage({1}, {2}, StrPtr({3}), {4}, {5}, {6}, {7}, {8}, {9})', p*)
Out := RegExReplace(Out, "[\s\,]*\)$", ")")
Out .= '`n`r' . gIndentation . "}"
return Out
}
if (p[3] ~= "^`".*") {
p[3] := 'StrPtr(' . p[3] . ')'
}

Out := format("ErrorLevel := SendMessage({1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9})", p*)
Return RegExReplace(Out, "[\s\,]*\)$", ")")
}
20 changes: 12 additions & 8 deletions convert/MaskCode.ahk
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
; 2026-06-26 ADDED by andymbody to support code block masking
; 2026-06-26 ADDED by andymbody to support code block masking
; currently supports nested classes and functions (as wells as block/line comments and quoted strings for v1 or v2)
; will add more support for other code blocks, AHK funcs, etc as needed
; all regex needles were designed to support masking tags. Feel free to contact me on AHK forum if I can assist with edits
Expand Down Expand Up @@ -543,16 +543,20 @@ class MLSTR extends PreMask
{
; Multi-line string block
; non-expression version [ = ], not [ := ]
; does not support block comments between declaration and opening parenthesis
; can using masking to support them, or update needle to support raw block comments

opt := '(*UCP)(?ims)' ; pattern options
LC := '(?:(?<=\s|);[^\v]*)' ; line comment (allows lead ws to be consumed already)
; 2024-07-06, UPDATED for better performance
opt := '(*UCP)(?ims)' ; pattern options
LC := '(?:(?<=\s);[^\v]*)' ; line comment (allows lead ws to be consumed already)
tagChar := (IsSet(gTagChar)) ? gTagChar : chr(0x2605)
TG := '(?:#TAG' tagChar '\w+' tagChar '#)' ; mask tags
CT := '(?<CT>(?:\s*(?:' LC '|' TG '))*)\h*' ; optional line comment OR tag
var := '(?<var>[_a-z]\w*)\h*=\h*' ; var - variable name
body := '\R+\h*(?<blk>\((?<guts>(?>.+?)+?)\R+\h*\))' ; body - block body with parentheses and guts
TG := '(?:#TAG' tagChar '\w+' tagChar '#)' ; mask tags
CT := '(?<CT>(?:\s*+(?:' LC '|' TG '))*)' ; optional line comment OR tag
var := '(?<var>[_a-z]\w*)\h*=\h*' ; var - variable name
body := '\h*\R+(?<blk>\h*\((?<guts>(?:\R*(?>[^\v]*))*?)\R+\h*+\))' ; body - block body with parentheses and guts
pattern := opt . var . CT . body
; (*UCP)(?ims)(?<var>[_a-z]\w*)\h*=\h*(?<CT>(?:\s*(?:(?:(?<=\s|);[^\v]*)|(?:#TAG?\w+?#)))*)\h*\R+\h*(?<blk>\((?<guts>(?>.+?)+?)\R+\h*\))
; changed to line-at-a-time vs character-at-a-time -> 4-5 times faster, only fooled if original code syntax is incorrect
; (*UCP)(?ims)(?<var>[_a-z]\w*)\h*=\h*(?<CT>(?:\s*+(?:(?:(?<=\s);[^\v]*)|(?:#TAG★\w+★#)))*+)\h*\R+(?<blk>\h*\((?<guts>(?:\R*(?>[^\v]*))*?)\R+\h*+\))
; A_Clipboard := pattern
; ExitApp
return pattern
Expand Down

0 comments on commit 18b3376

Please sign in to comment.