-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathConvertFuncs.ahk
4853 lines (4554 loc) · 204 KB
/
ConvertFuncs.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#Requires AutoHotKey v2.0
#SingleInstance Force
; to do: strsplit (old command)
; requires should change the version :D
global dbg := 0
#Include lib/ClassOrderedMap.ahk
#Include lib/dbg.ahk
#Include Convert/1Commands.ahk
#Include Convert/2Functions.ahk
#Include Convert/3Methods.ahk
#Include Convert/4ArrayMethods.ahk
#Include Convert/5Keywords.ahk
#Include Convert/MaskCode.ahk ; 2024-06-26 ADDED AMB (masking support)
;################################################################################
Convert(ScriptString) ; MAIN ENTRY POINT for conversion process
;################################################################################
{
; PLEASE DO NOT PLACE ANY OF YOUR CODE IN THIS FUNCTION
; Please place any code that must be performed BEFORE _convertLines()...
; ... into the following function
Before_LineConverts(&ScriptString)
; DO NOT PLACE YOUR CODE HERE
; perform conversion of main/global portion of script only
convertedCode := _convertLines(ScriptString,finalize:=0)
; Please place any code that must be performed AFTER _convertLines()...
; ... into the following function
After_LineConverts(&convertedCode)
return convertedCode
}
;################################################################################
Before_LineConverts(&code)
{
;#### Please place CALLS TO YOUR FUNCTIONS here - not boilerplate code #####
; initialize all global vars here so ALL code has access to them
setGlobals()
; 2024-07-09 AMB, UPDATED - for label renaming support
; these must also be declared global here because they are being updated here
global gAllFuncNames := getFuncNames(code) ; comma-delim stringList of all function names
global gAllV1LabelNames := getV1LabelNames(&code) ; comma-delim stringList of all orig v1 label names
; captures all v1 labels from script...
; ... converts v1 names to v2 compatible...
; ... and places them in gmAllLabelsV1toV2 map for easy access
global gmAllLabelsV1toV2 := map()
getScriptLabels(code)
; 2024-07-02 AMB, for support of MenuBar detection
global gMenuBarName := getMenuBarName(code) ; name of GUI main menubar
; turn masking on/off at top of SetGlobals()
if (gUseMasking)
{
; 2024-07-01 ADDED, AMB - For fix of #74
; multiline string blocks (are returned converted)
maskMLStrings(&code) ; mask multiline string blocks
; convert and mask classes and functions
maskBlocks(&code) ; see MaskCode.ahk
}
return ; code by reference
}
;################################################################################
After_LineConverts(&code)
{
;#### Please place CALLS TO YOUR FUNCTIONS here - not boilerplate code #####
; turn masking on/off at top of SetGlobals()
if (gUseMasking)
{
; remove masking from classes, functions, multiline string
; classes, funcs, ml-strings are returned as v2 converted
restoreBlocks(&code) ; see MaskCode.ahk
restoreMLStrings(&code) ; 2024-07-01 - converts prior to restore
}
; inspect to see whether your code is best placed here or in FinalizeConvert()
; operations that must be performed last
FinalizeConvert(&code) ; perform all final operations
TrueFinalizeConvert(&code) ; final operations not in block node conversions, please use FinalizeConvert() when possible
return ; code by reference
}
;################################################################################
setGlobals()
{
; 2024-07-11 AMB, ADDED dedicated function for global declarations
; ... so that they can be initialized prior to any other code...
; ... this is being done to fix a bug between global masking and onMessage handling
; ... and so all code within script has access to these globals prior to _convertLines() call
global gUseMasking := 1 ; 2024-06-26 - set to 0 to test without masking applied
global gMenuBarName := "" ; 2024-07-02 - holds the name of the main gui menubar
global gAllFuncNames := "" ; 2024-07-07 - comma-deliminated string holding the names of all functions
global gmAllLabelsV1toV2 := map() ; 2024-07-07 - map holding v1 labelNames (key) and their new v2 labelName (value)
global gAllV1LabelNames := "" ; 2024-07-09 - comma-deliminated string holding the names of all v1 labels
global gaScriptStrsUsed := Array() ; Keeps an array of interesting strings used in the script
global gaWarnings := Array() ; Keeps track of global warning to add, see FinalizeConvert()
global gaList_PseudoArr := Array() ; list of strings that should be converted from pseudoArray to Array
global gaList_MatchObj := Array() ; list of strings that should be converted from Match Object V1 to Match Object V2
global gaList_LblsToFuncO := Array() ; array of objects with the properties [label] and [parameters] that should be converted from label to Function
global gaList_LblsToFuncC := Array() ; List of labels that were converted to funcs, automatically added when gaList_LblsToFuncO is pushed to
global gOrig_Line := ""
global gOrig_Line_NoComment := ""
global gOScriptStr := "" ; array of all the lines
global gO_Index := 0 ; current index of the lines
global gIndentation := ""
global gSingleIndent := ""
global gGuiNameDefault := "myGui"
global gGuiList := "|"
global gmGuiVList := Map() ; Used to list all variable names defined in a Gui
global gGuiActiveFont := ""
global gGuiControlCount := 0
global gMenuList := "|"
global gmMenuCBChecks := map() ; 2024-06-26 AMB, for fix #131
global gmGuiFuncCBChecks := map() ; same as above for gui funcs
global gmGuiCtrlType := map() ; Create a map to return the type of control
global gmGuiCtrlObj := map() ; Create a map to return the object of a control
global gUseLastName := False ; Keep track of if we use the last set name in gGuiList
global gmOnMessageMap := map() ; Create a map of OnMessage listeners
global gmVarSetCapacityMap := map() ; A list of VarSetCapacity variables, with definition type
global gmByRefParamMap := map() ; Map of FuncNames and ByRef params
global gNL_Func := "" ; _Funcs can use this to add New Previous Line
global gEOLComment_Func := "" ; _Funcs can use this to add comments at EOL
global gfrePostFuncMatch := False ; ... to know their regex matched
global gfNoSideEffect := False ; ... to not change global variables
global gLVNameDefault := "LV"
global gTVNameDefault := "TV"
global gSBNameDefault := "SB"
global gFuncParams := ""
global gAhkCmdsToRemove, gmAhkCmdsToConvert, gmAhkFuncsToConvert, gmAhkMethsToConvert
, gmAhkArrMethsToConvert, gmAhkKeywdsToRename, gmAhkLoopRegKeywds
}
;################################################################################
; MAIN CONVERSION LOOP - handles each line separately
_convertLines(ScriptString, finalize:=!gUseMasking) ; 2024-06-26 RENAMED to accommodate masking
;################################################################################
{
; 2024-07-11 AMB, Globals are now declared/initialize in SetGlobals()...
; ... so that all functions can have access to them prior to this function being called
; ... moving them fixes masking issue with OnMessage
global gmAltLabel := GetAltLabelsMap(ScriptString) ; Create a map of labels who are identical
global gOrig_ScriptStr := ScriptString
global gOrig_Line_NoComment := ""
global gOScriptStr := StrSplit(ScriptString, "`n", "`r") ; array for all the lines
global gO_Index := 0 ; current index of the lines
global gIndentation := ""
global gSingleIndent := (RegExMatch(ScriptString, "(^|[\r\n])( +|\t)", &ws)) ? ws[2] : " " ; First spaces or single tab found
global gNL_Func := "" ; _Funcs can use this to add New Previous Line
global gEOLComment_Func := "" ; _Funcs can use this to add comments at EOL
global gaScriptStrsUsed
ScriptOutput := ""
lastLine := ""
InCommentBlock := false
InCont := 0
Cont_String := 0
gaScriptStrsUsed.ErrorLevel := InStr(ScriptString, "ErrorLevel")
gaScriptStrsUsed.StringCaseSense := InStr(ScriptString, "StringCaseSense") ; Both command and A_ variable
; parse each line of the input script
Loop
{
gO_Index++
; ToolTip("Converting line: " gO_Index)
if (gOScriptStr.Length < gO_Index) {
; This allows the user to add or remove lines if necessary
; Do not forget to change the gO_Index if you want to remove or add the line above or lines below
break
}
O_Loopfield := gOScriptStr[gO_Index]
Skip := false
Line := O_Loopfield
gOrig_Line := Line
RegExMatch(Line, "^(\h*)", &gIndentation)
gIndentation := gIndentation[1]
;msgbox, % "Line:`n" Line "`n`nIndentation=[" gIndentation "]`nStrLen(gIndentation)=" StrLen(gIndentation)
FirstChar := SubStr(Trim(Line), 1, 1)
FirstTwo := SubStr(LTrim(Line), 1, 2)
;msgbox, FirstChar=%FirstChar%`nFirstTwo=%FirstTwo%
; Save directive values needed in later conversions
if (RegExMatch(Line, "i)^\h*#(CommentFlag|EscapeChar|DerefChar|Delimiter)\h+.", &match) && InCont = false) {
if (match[1] = "CommentFlag") {
if (RegExMatch(Line, "i)#CommentFlag\h+(.{1,15})\h*$", &dMatch))
gaScriptStrsUsed.CommentFlag := dMatch[1]
} else if (match[1] = "EscapeChar") {
if (RegExMatch(Line, "i)#EscapeChar\h+(.)\h*$", &dMatch) && dMatch != "``")
gaScriptStrsUsed.EscapeChar := dMatch[1]
} else if (match[1] = "DerefChar") {
if (RegExMatch(Line, "i)#DerefChar\h+(.)\h*$", &dMatch))
gaScriptStrsUsed.DerefChar := dMatch[1]
} else if (match[1] = "Delimiter") {
if (RegExMatch(Line, "i)#Delimiter\h+(.)\h*$", &dMatch))
gaScriptStrsUsed.Delimiter := dMatch[1]
}
}
if (!RegExMatch(Line, "i)^\h*#(CommentFlag|EscapeChar|DerefChar|Delimiter)\h+.") && !InCont)
&& HasProp(gaScriptStrsUsed, "CommentFlag") {
char := HasProp(gaScriptStrsUsed, "EscapeChar") ? gaScriptStrsUsed.EscapeChar : "``"
Line := RegExReplace(Line, "(?<!\Q" char "\E)\Q" gaScriptStrsUsed.CommentFlag "\E", ";")
}
if (RegExMatch(Line, "(\h+`;.*)$", &EOLComment))
{
EOLComment := EOLComment[1]
Line := RegExReplace(Line, "(\h+`;.*)$", "")
;msgbox, % "Line:`n" Line "`n`nEOLComment:`n" EOLComment
} else if (FirstChar == ";")
{
EOLComment := Line
Line := ""
} else
EOLComment := ""
CommandMatch := -1
; get PreLine of line with hotkey and hotstring definition, String will be temporary removed form the line
; Prelines is code that does not need to changes anymore, but coud prevent correct command conversion
PreLine := ""
; Code that gets appended to end of current line
; Useful for code that requires something on the second line
; !USE gIndentation!
PostLine := ""
if (RegExMatch(Line, "((^\s*|\s*&\s*)([^,\s]*|[$~!^#+]*,))+::.*$") && (FirstTwo != "::")) {
LineNoHotkey := RegExReplace(Line, "(^\s*).+::(.*$)", "$2")
if (LineNoHotkey != "") {
PreLine .= RegExReplace(Line, "^(\s*.+::).*$", "$1")
Line := LineNoHotkey
}
}
if (RegExMatch(Line, "^\s*({\s*).*$")) {
LineNoHotkey := RegExReplace(Line, "(^\s*)({\s*)(.*$)", "$3")
if (LineNoHotkey != "") {
PreLine .= RegExReplace(Line, "(^\s*)({\s*)(.*$)", "$1$2")
Line := LineNoHotkey
}
}
if (RegExMatch(Line, "i)^\s*(}?\s*(Try|Else)\s*[\s{]\s*).*$")) {
LineNoHotkey := RegExReplace(Line, "i)(^\s*)(}?\s*(Try|Else)\s*[\s{]\s*)(.*$)", "$4")
if (LineNoHotkey != "") {
PreLine .= RegExReplace(Line, "i)(^\s*)(}?\s*(Try|Else)\s*[\s{]\s*)(.*$)", "$1$2")
Line := LineNoHotkey
}
}
gOrig_Line := Line
if (!RegExMatch(Line, "i)^\h*#(CommentFlag|EscapeChar|DerefChar|Delimiter)\h+.") && !InCont) {
deref := "``"
if (HasProp(gaScriptStrsUsed, "EscapeChar")) {
deref := gaScriptStrsUsed.EscapeChar
Line := StrReplace(Line, "``", "``````")
Line := StrReplace(Line, gaScriptStrsUsed.EscapeChar, "``")
}
if (HasProp(gaScriptStrsUsed, "DerefChar")) {
Line := RegExReplace(Line, "(?<!\Q" deref "\E)\Q" gaScriptStrsUsed.DerefChar "\E", "%")
}
if (HasProp(gaScriptStrsUsed, "Delimiter")) {
Line := RegExReplace(Line, "(?<!\Q" deref "\E)\Q" gaScriptStrsUsed.Delimiter "\E", ",")
}
}
; Fix lines with preceeding }
LinePrefix := ""
if (RegExMatch(Line, "i)^\s*}(?!\s*else|\s*\n)\s*", &Equation)) {
Line := StrReplace(Line, Equation[],,,, 1)
LinePrefix := Equation[]
}
; Remove comma after flow commands
if (RegExMatch(Line, "i)^(\s*)(else|for|if|loop|return|while)(\s*,\s*|\s+)(.*)$", &Equation)) {
Line := Equation[1] Equation[2] " " Equation[4]
}
; Handle return % var -> return var
if (RegExMatch(Line, "i)^(.*)(return)(\s+%\s*\s+)(.*)$", &Equation)) {
Line := Equation[1] Equation[2] " " Equation[4]
}
; -------------------------------------------------------------------------------
; skip comment blocks with one statement
;
else if (FirstTwo == "/*") {
line .= EOLComment ; done here because of the upcoming "continue"
EOLComment := ""
loop {
gO_Index++
if (gOScriptStr.Length < gO_Index) {
break
}
LineContSect := gOScriptStr[gO_Index]
Line .= "`r`n" . LineContSect
FirstTwo := SubStr(LTrim(LineContSect), 1, 2)
if (FirstTwo == "*/") {
; End Comment block
break
}
}
ScriptOutput .= Line . "`r`n"
; Output and NewInput should become arrays, NewInput is a copy of the Input, but with empty lines added for easier comparison.
LastLine := Line
continue ; continue with the next line
}
; Check for , continuation sections add them to the line
; https://www.autohotkey.com/docs/Scripts.htm#continuation
loop
{
if (gOScriptStr.Length < gO_Index + 1) {
break
}
FirstNextLine := SubStr(LTrim(gOScriptStr[gO_Index + 1]), 1, 1)
; 2024-06-30, AMB - FIXED - these are incorrect, they both capture first character only
FirstTwoNextLine := SubStr(LTrim(gOScriptStr[gO_Index + 1]), 1, 2) ; now captures 2 chars
ThreeNextLine := SubStr(LTrim(gOScriptStr[gO_Index + 1]), 1, 3) ; now captures 3 chars
if (FirstNextLine ~= "[,\.]" || FirstTwoNextLine ~= "\?\h" ; tenary (?)
|| FirstTwoNextLine = "||"
|| FirstTwoNextLine = "&&"
|| FirstTwoNextLine = "or"
|| ThreeNextLine = "and"
|| ThreeNextLine ~= ":\h(?!:)") ; tenary (:) - fix hotkey mistaken for tenary colon
{
gO_Index++
; 2024-06-30, AMB Fix missing linefeed and comments - Issue #72
Line .= "`r`n" . RegExReplace(gOScriptStr[gO_Index], "(\h+`;.*)$", "")
} else {
break
}
}
; Loop the functions
gfNoSideEffect := False
subLoopFunctions(ScriptString, Line, &LineFuncV2, &gotFunc:=False)
if (gotFunc) {
Line := LineFuncV2
}
; Add warning for Array.MinIndex()
if (Line ~= "([^(\s]*\.)ϨMinIndex\(placeholder\)Ϩ")
EOLComment .= ' `; V1toV2: Not perfect fix, fails on cases like [ , "Should return 2"]'
; Remove case from switch to ensure conversion works
CaseValue := ""
if (RegExMatch(Line, "i)^\s*(?:case .*?|default):(?!=)", &Equation)) {
CaseValue := Equation[]
Line := StrReplace(Line, CaseValue,,,, 1)
}
gOrig_Line_NoComment := Line
; -------------------------------------------------------------------------------
; check if this starts a continuation section
;
; no idea what that RegEx does, but it works to prevent detection of ternaries
; got that RegEx from Coco here: https://github.com/cocobelgica/AutoHotkey-Util/blob/master/EnumIncludes.ahk#L65
; and modified it slightly
;
if (FirstChar == "(")
&& RegExMatch(Line, "i)^\s*\((?:\s*(?(?<=\s)(?!;)|(?<=\())(\bJoin\S*|[^\s)]+))*(?<!:)(?:\s+;.*)?$")
{
InCont := 1
;if (RegExMatch(Line, "i)join(.+?)(LTrim|RTrim|Comment|`%|,|``)?", &Join))
;JoinBy := Join[1]
;else
;JoinBy := "``n"
;MsgBox, Start of continuation section`nLine:`n%Line%`n`nLastLine:`n%LastLine%`n`nScriptOutput:`n[`n%ScriptOutput%`n]
if (InStr(LastLine, ':= ""'))
{
; if LastLine was something like: var := ""
; that means that the line before conversion was: var =
; and this new line is an opening ( for continuation section
; so remove the last quote and the newline `r`n chars so we get: var := "
; and then re-add the newlines
ScriptOutput := SubStr(ScriptOutput, 1, -3) . "`r`n"
;MsgBox, Output after removing one quote mark:`n[`n%ScriptOutput%`n]
Cont_String := 1
;;;Output.Seek(-4, 1) ; Remove the newline characters and double quotes
} else
{
;;;Output.Seek(-2, 1)
;;;Output.Write(" `% ")
}
;continue ; Don't add to the output file
} else if (FirstChar == ")")
{
;MsgBox "End Cont. Section`n`nLine:`n" Line "`n`nLastLine:`n" LastLine "`n`nScriptOutput:`n[`n" ScriptOutput "`n]"
InCont := 0
if (Cont_String = 1)
{
if (FirstTwo != ")`"") { ; added as an exception for quoted continuation sections
Line := RegExReplace(Line, "\)", ")`"", , 1)
}
ScriptOutput .= Line . "`r`n"
LastLine := Line
continue
}
} else if (InCont)
{
;Line := ToExp(Line . JoinBy)
;if (InCont > 1)
;Line := ". " . Line
;InCont++
Line := RegexReplace(Line, "%(.*?)%", "`" $1 `"")
;MsgBox "Inside Cont. Section`n`nLine:`n" Line "`n`nLastLine:`n" LastLine "`n`nScriptOutput:`n[`n" ScriptOutput "`n]"
ScriptOutput .= Line . "`r`n"
LastLine := Line
continue
}
; -------------------------------------------------------------------------------
; Replace = with := expression equivilents in "var = value" assignment lines
;
; var = 3 will be replaced with var := "3"
; lexikos says var=value should always be a string, even numbers
; https://autohotkey.com/boards/viewtopic.php?p=118181#p118181
;
else if (RegExMatch(Line, "(?i)^(\h*[a-z_%][a-z_0-9%]*\h*)=([^;\v]*)", &Equation))
{
; msgbox("assignment regex`norigLine: " Line "`norig_left=" Equation[1] "`norig_right=" Equation[2] "`nconv_right=" ToStringExpr(Equation[2]))
Line := RTrim(Equation[1]) . " := " . ToStringExpr(Equation[2]) ; regex above keeps the gIndentation already
}
else if (RegExMatch(Line, "i)((global|local|static).*)(?<!:)="))
{
maskStrings(&Line)
While RegExMatch(Line, "i)((global|local|static).*)(?<!:)=") {
Line := RegExReplace(Line, "i)((global|local|static).*)(?<!:)=", "$1:=")
}
If InStr(Line, ",")
EOLComment .= " `; V1toV2: Assuming this is v1.0 code"
restoreStrings(&Line)
}
Else if (RegExMatch(Line, "(?i)^(\h*[a-z_][a-z_0-9]*\h*):=(\h*)$", &Equation)) ; var := should become var := ""
{
Line := RTrim(Equation[1]) . ' := ""' . Equation[2]
}
else if (RegexMatch(Line, "(?i)^(\h*[a-z_][a-z_0-9]*\h*[:*\.]=\h*)(.*)") && InStr(Line, '""')) ; Line is var assignment, and has ""
{
; Fixes issues with continuation sections
Line := RegExReplace(Line, '""(\h*)\r\n', '"' Chr(0x2700) '"$1`r`n')
maskFuncCalls(&Line)
maskStrings(&Line)
LineSplit := []
for , Line in StrSplit(Line, ",") {
restoreStrings(&Line)
ternary := 0
if (RegexMatch(Line, "(?i)^(\h*[a-z_][a-z_0-9]*\h*[:*\.]=\h*)(.*)", &Equation) && InStr(Line, '""')) {
; 2024-08-02 AMB, Fix 272
If (InStr(Line, "?") && InStr(Line, ":")) { ; Ternary
Line := Equation[1], val := Equation[2]
maskStrings(&val)
If (!InStr(val, "?") || !InStr(val, ":")) {
ternary := 0
Line := Line restoreStrings(&val)
} else {
ternary := 1
val := StrReplace(val, ":=", Chr(0x2727) "assign" Chr(0x2727))
val := StrReplace(val, ":", ":" Chr(0x2828))
val := StrReplace(val, "?", "?" Chr(0x2929))
valSplit := StrSplit(val, [":", "?"])
val := ""
for , chunk in valSplit {
restoreStrings(&chunk)
if InStr(chunk, '""')
ConvertDblQuotes2(&val, chunk)
else
val .= chunk
}
Line .= val
Line := StrReplace(Line, Chr(0x2929), "?")
Line := StrReplace(Line, Chr(0x2828), ":")
Line := StrReplace(Line, Chr(0x2727) "assign" Chr(0x2727), ":=")
}
}
If !ternary {
maskStrings(&line), Line := Equation[1], val := Equation[2]
if (!RegexMatch(Line, "\h*\w+(\((?>[^)(]+|(?-1))*\))")) ; not a func
{
ConvertDblQuotes2(&Line, val)
}
}
}
LineSplit.Push(Line)
}
Line := ""
for , v in LineSplit
Line .= v ","
Line := RTrim(Line, ",")
Line := RegExReplace(Line, Chr(0x2700))
restoreStrings(&line)
restoreFuncCalls(&Line)
}
; -------------------------------------------------------------------------------
; Traditional-if to Expression-if
;
else if (RegExMatch(Line, "i)^\s*(else\s+)?if\s+(not\s+)?([a-z_][a-z_0-9]*[\s]*)(!=|=|<>|>=|<=|<|>)([^{;]*)(\s*{?\s*)(.*)", &Equation))
{
;msgbox if regex`nLine: %Line%`n1: %Equation[1]%`n2: %Equation[2]%`n3: %Equation[3]%`n4: %Equation[4]%`n5: %Equation[5]%`n6: %Equation[6]%
; Line := gIndentation . format_v("{else}if {not}({variable} {op} {value}){otb}"
; , { else: Equation[1]
; , not: Equation[2]
; , variable: RTrim(Equation[3])
; , op: Equation[4]
; , value: ToExp(Equation[5])
; , otb: Equation[6] } )
op := (Equation[4] = "<>") ? "!=" : Equation[4]
; not used,
; Line := gIndentation . format("{1}if {2}({3} {4} {5}){6}"
; , Equation[1] ;else
; , Equation[2] ;not
; , RTrim(Equation[3]) ;variable
; , op ;op
; , ToExp(Equation[5]) ;value
; , Equation[6] ) ;otb
; Preline hack for furter commands
PreLine := gIndentation PreLine . format("{1}if {2}({3} {4} {5}){6}"
, Equation[1] ;else
, Equation[2] ;not
, RTrim(Equation[3]) ;variable
, op ;op
, ToExp(Equation[5]) ;value
, Equation[6]) ;otb
Line := Equation[7]
}
; -------------------------------------------------------------------------------
; if var between
;
else if (RegExMatch(Line, "i)^\s*(else\s+)?if\s+([a-z_][a-z_0-9]*) (\s*not\s+)?between ([^{;]*) and ([^{;]*)(\s*{?\s*)(.*)", &Equation))
{
;msgbox if regex`nLine: %Line%`n1: %Equation[1]%`n2: %Equation[2]%`n3: %Equation[3]%`n4: %Equation[4]%`n5: %Equation[5]%
; Line := gIndentation . format_v("{else}if {not}({var} >= {val1} && {var} <= {val2}){otb}"
; , { else: Equation[1]
; , var: Equation[2]
; , not: (Equation[3]) ? "!" : ""
; , val1: ToExp(Equation[4])
; , val2: ToExp(Equation[5])
; , otb: Equation[6] } )
val1 := ToExp(Equation[4])
val2 := ToExp(Equation[5])
if (isNumber(val1) && isNumber(val2)) || InStr(Equation[4], "%") || InStr(Equation[5], "%")
{
PreLine .= gIndentation . format("{1}if {3}({2} >= {4} && {2} <= {5}){6}"
, Equation[1] ;else
, Equation[2] ;var
, (Equation[3]) ? "!" : "" ;not
, val1 ;val1
, val2 ;val2
, Equation[6]) ;otb
} else ; if not numbers or variables, then compare alphabetically with StrCompare()
{
;if ((StrCompare(var, "blue") >= 0) && (StrCompare(var, "red") <= 0))
PreLine .= gIndentation . format("{1}if {3}((StrCompare({2}, {4}) >= 0) && (StrCompare({2}, {5}) <= 0)){6}"
, Equation[1] ;else
, Equation[2] ;var
, (Equation[3]) ? "!" : "" ;not
, val1 ;val1
, val2 ;val2
, Equation[6]) ;otb
}
Line := Equation[7]
}
; -------------------------------------------------------------------------------
; if var in
;
else if (RegExMatch(Line, "i)^\s*(else\s+)?if\s+([a-z_][a-z_0-9]*) (\s*not\s+)?in ([^{;]*)(\s*{?\s*)(.*)", &Equation))
{
;msgbox if regex`nLine: %Line%`n1: %Equation[1]%`n2: %Equation[2]%`n3: %Equation[3]%`n4: %Equation[4]%`n5: %Equation[5]%
; Line := gIndentation . format_v("{else}if {not}({var} in {val1}){otb}"
; , { else: Equation[1]
; , var: Equation[2]
; , not: (Equation[3]) ? "!" : ""
; , val1: ToExp(Equation[4])
; , otb: Equation[6] } )
if (RegExMatch(Equation[4], "^%")) {
val1 := "`"^(?i:`" RegExReplace(RegExReplace(" ToExp(Equation[4]) ",`"[\\\.\*\?\+\[\{\|\(\)\^\$]`",`"\$0`"),`"\s*,\s*`",`"|`") `")$`""
} else if (RegExMatch(Equation[4], "^[^\\\.\*\?\+\[\{\|\(\)\^\$]*$")) {
val1 := "`"^(?i:" RegExReplace(Equation[4], "\s*,\s*", "|") ")$`""
} else {
val1 := "`"^(?i:" RegExReplace(RegExReplace(Equation[4], "[\\\.\*\?\+\[\{\|\(\)\^\$]", "\$0"), "\s*,\s*", "|") ")$`""
}
PreLine .= gIndentation . format("{1}if {3}({2} ~= {4}){5}"
, Equation[1] ;else
, Equation[2] ;var
, (Equation[3]) ? "!" : "" ;not
, val1 ;val1
, Equation[5]) ;otb
Line := Equation[6]
}
; -------------------------------------------------------------------------------
; if var contains
;
else if (RegExMatch(Line, "i)^\s*(else\s+)?if\s+([a-z_][a-z_0-9]*) (\s*not\s+)?contains ([^{;]*)(\s*{?\s*)(.*)", &Equation))
{
;msgbox if regex`nLine: %Line%`n1: %Equation[1]%`n2: %Equation[2]%`n3: %Equation[3]%`n4: %Equation[4]%`n5: %Equation[5]%
; Line := gIndentation . format_v("{else}if {not}({var} contains {val1}){otb}"
; , { else: Equation[1]
; , var: Equation[2]
; , not: (Equation[3]) ? "!" : ""
; , val1: ToExp(Equation[4])
; , otb: Equation[6] } )
if (RegExMatch(Equation[4], "^%")) {
val1 := "`"i)(`" RegExReplace(RegExReplace(" ToExp(Equation[4]) ",`"[\\\.\*\?\+\[\{\|\(\)\^\$]`",`"\$0`"),`"\s*,\s*`",`"|`") `")`""
} else if (RegExMatch(Equation[4], "^[^\\\.\*\?\+\[\{\|\(\)\^\$]*$")) {
val1 := "`"i)(" RegExReplace(Equation[4], "\s*,\s*", "|") ")`""
} else {
val1 := "`"i)(" RegExReplace(RegExReplace(Equation[4], "[\\\.\*\?\+\[\{\|\(\)\^\$]", "\$0"), "\s*,\s*", "|") ")`""
}
PreLine .= gIndentation . format("{1}if {3}({2} ~= {4}){5}"
, Equation[1] ;else
, Equation[2] ;var
, (Equation[3]) ? "!" : "" ;not
, val1 ;val1
, Equation[5]) ;otb
Line := Equation[6]
}
; -------------------------------------------------------------------------------
; if var is type
;
else if (RegExMatch(Line, "i)^\s*(else\s+)?if\s+([a-z_][a-z_0-9]*) is (not\s+)?([^{;]*)(\s*{?\s*)(.*)", &Equation))
{
;msgbox if regex`nLine: %Line%`n1: %Equation[1]%`n2: %Equation[2]%`n3: %Equation[3]%`n4: %Equation[4]%`n5: %Equation[5]%
; Line := gIndentation . format_v("{else}if {not}({variable} is {type}){otb}"
; , { else: Equation[1]
; , not: (Equation[3]) ? "!" : ""
; , variable: Equation[2]
; , type: ToStringExpr(Equation[4])
; , otb: Equation[5] } )
PreLine .= gIndentation . format("{1}if {3}is{4}({2}){5}"
, Equation[1] ;else
, Equation[2] ;var
, (Equation[3]) ? "!" : "" ;not
, StrTitle(Equation[4]) ;type
, Equation[5]) ;otb
Line := Equation[6]
}
; -------------------------------------------------------------------------------
; Replace all switch variations with Switch SwitchValue
;
else if (RegExMatch(Line, "i)^\s*switch,?\s*([^{]*)\s*(\{?)", &Equation))
{
Line := "Switch " Equation[1] Equation[2]
}
; -------------------------------------------------------------------------------
; Replace = with := in function default params
;
else if (RegExMatch(Line, "i)^\s*(\w+)\((.+)\)", &MatchFunc))
&& !(MatchFunc[1] ~= "i)\b(if|while)\b") ; skip if(expr) and while(expr) when no space before paren
; this regex matches anything inside the parentheses () for both func definitions, and func calls :(
{
; Changing the ByRef parameters to & signs.
If RegExMatch(Line, "i)(\bByRef\s+)") {
ByRefTrackArray := [] ; for each param of a func, 1 if byef, 0 otherwise
params := MatchFunc[2]
while pos := RegExMatch(params, "[^,]+", &MatchFuncParams) {
if RegExMatch(MatchFuncParams[], "i)(\bByRef\s+)") {
ByRefTrackArray.Push(true)
} else {
ByRefTrackArray.Push(false)
}
params := StrReplace(params, MatchFuncParams[],,,, 1)
}
gmByRefParamMap.Set(MatchFunc[1], ByRefTrackArray)
; Moved replacement to FixByRefParams()
; Line := RegExReplace(Line, "i)(\bByRef\s+)", "&")
}
AllParams := MatchFunc[2]
;msgbox, % "function line`n`nLine:`n" Line "`n`nAllParams:`n" AllParams
; first replace all commas and question marks inside quoted strings with placeholders
; - commas: because we will use comma as delimeter to parse each individual param
; - question mark: because we will use that to determine if there is a ternary
pos := 1, quoted_string_match := ""
while (pos := RegExMatch(AllParams, '".*?"', &MatchObj, pos + StrLen(quoted_string_match))) ; for each quoted string
{
quoted_string_match := MatchObj[0]
;msgbox, % "quoted_string_match=" quoted_string_match "`nlen=" StrLen(quoted_string_match) "`npos=" pos
string_with_placeholders := StrReplace(quoted_string_match, ",", "MY_COMMª_PLA¢E_HOLDER")
string_with_placeholders := StrReplace(string_with_placeholders, "?", "MY_¿¿¿_PLA¢E_HOLDER")
string_with_placeholders := StrReplace(string_with_placeholders, "=", "MY_ÈQÜAL§_PLA¢E_HOLDER")
;msgbox, %string_with_placeholders%
Line := StrReplace(Line, quoted_string_match, string_with_placeholders, "Off", &Cnt, 1)
}
;msgbox, % "Line:`n" Line
; get all the params again, this time from our line with the placeholders
if (RegExMatch(Line, "i)^\s*\w+\((.+)\)", &MatchFunc2))
{
AllParams2 := MatchFunc2[1]
pos := 1, match := ""
Loop Parse, AllParams2, "," ; for each individual param (separate by comma)
{
thisprm := A_LoopField
;msgbox, % "Line:`n" Line "`n`nthisparam:`n" thisprm
if (RegExMatch(A_LoopField, "i)([\s]*[a-z_][a-z_0-9]*[\s]*)=([^,\)]*)", &ParamWithEquals))
{
;msgbox, % "Line:`n" Line "`n`nParamWithEquals:`n" ParamWithEquals[0] "`n" ParamWithEquals[1] "`n" ParamWithEquals[2]
; replace the = with :=
; question marks were already replaced above if they were within quotes
; so if a questionmark still exists then it must be for ternary during a func call
; which we will exclude. for example: MyFunc((var=5) ? 5 : 0)
if (!InStr(A_LoopField, "?"))
{
TempParam := ParamWithEquals[1] . ":=" . ParamWithEquals[2]
;msgbox, % "Line:`n" Line "`n`nParamWithEquals:`n" ParamWithEquals[0] "`n" TempParam
Line := StrReplace(Line, ParamWithEquals[0], TempParam, "Off", &Cnt, 1)
;msgbox, % "Line after replacing = with :=`n" Line
}
}
}
}
; deref the placeholders
Line := StrReplace(Line, "MY_COMMª_PLA¢E_HOLDER", ",")
Line := StrReplace(Line, "MY_¿¿¿_PLA¢E_HOLDER", "?")
Line := StrReplace(Line, "MY_ÈQÜAL§_PLA¢E_HOLDER", "=")
}
; -------------------------------------------------------------------------------
; Fix return %var% -> return var
;
; we use the same parsing method as the next else clause below
;
else if (Trim(SubStr(Line, 1, FirstDelim := RegExMatch(Line, "\w[,\s]"))) = "return")
{
Params := SubStr(Line, FirstDelim + 2)
if (RegExMatch(Params, "^%\w+%$")) ; if the var is wrapped in %%, then remove them
{
Params := SubStr(Params, 2, -1)
Line := gIndentation . "return " . Params . EOLComment
}
}
; Moving the if/else/While statement to the preline
;
else if (RegExMatch(Line, "i)(^\s*[\}]?\s*(else|while|if)[\s\(][^\{]*{\s*)(.*$)", &Equation)) {
PreLine .= Equation[1]
Line := Equation[3]
}
; Remove [] from classes with no params
else if (RegExMatch(Line, "(.+)\[\](\s*{?)", &Equation)) {
If SubStr(Line, -1) = "{" or RegExMatch(gOScriptStr[gO_Index + 1], "\s*{")
Line := Equation[1] Equation[2]
}
If RegExMatch(Line, "i)^(\s*Return\s*)(.*)", &Equation) && InStr(Equation[2], ",") {
maskFuncCalls(&Line) ; Make code look nicer
maskStrings(&Line) ; By checking if comma is part of string or func
if InStr(Line, ",")
Line := Equation[1] "(AHKv1v2_Temp := " Equation[2] ", AHKv1v2_Temp) `; V1toV2: Wrapped Multi-statement return with parentheses"
restoreStrings(&Line)
restoreFuncCalls(&Line)
}
If IsSet(linesInIf) && linesInIf != "" {
linesInIf++
;MsgBox "Line: [" Line "]`nlinesInIf: [" linesInIf "]`nPreLine [" PreLine "]"
If (Trim(Line) ~= "i)else\s+if" || Trim(PreLine) ~= "i)else\s+if")
; else if - reset search
linesInIf := 0
Else If (Trim(Line) = "")
; line is comment or blank - reset search
linesInIf--
Else If (Trim(Line) ~= "i)else(?!\s+if)")
|| (SubStr(Trim(Line), 1, 1) = "{") ; Fails if { is on line further than next
|| (linesInIf >= 2)
; just else - cancel search
; { on next line - "
; search is too long - "
linesInIf := ""
Else If (PreLine ~= "i)\s*try" && !InStr(PreLine, "{")) {
PreLine := StrReplace(PreLine, "try", gIndentation "{`ntry")
PostLine .= "`n" gIndentation "}"
}
}
If (SubStr(Trim(Line), 1, 2) = "if" && !InStr(Line, "{"))
|| (SubStr(Trim(PreLine), 1, 2) = "if")
linesInIf := 0
if (RegExMatch(Line, "i)(^\s*)([a-z_][a-z_0-9]*)\s*\+=\s*(.*?)\s*,\s*([SMHD]\w*)(.*$)", &Equation)) {
Line := Equation[1] Equation[2] " := DateAdd(" Equation[2] ", " ParameterFormat("ValueCBE2E", Equation[3]) ", '" Equation[4] "')" Equation[5]
} else if (RegExMatch(Line, "i)(^\s*)([a-z_][a-z_0-9]*)\s*\-=\s*(.*?)\s*,\s*([SMHD]\w*)(.*$)", &Equation)) {
Line := Equation[1] Equation[2] " := DateDiff(" Equation[2] ", " ParameterFormat("ValueCBE2E", Equation[3]) ", '" Equation[4] "')" Equation[5]
}
; Convert Assiociated Arrays to Map Maybe not always wanted...
if (RegExMatch(Line, "i)^(\s*)((global|local|static)\s+)?([a-z_0-9]+)(\s*:=\s*)(\{[^;]*)", &Equation)) {
; Only convert to a map if for in statement is used for it
if (RegExMatch(ScriptString, "is).*for\s[\s,a-z0-9_]*\sin\s" Equation[4] "[^\.].*")) {
Line := AssArr2Map(Line)
}
}
; Fixing ternary operations [var ? : "1"] => [var ? "" : "1"]
if (RegExMatch(Line, "im)^(.*)(\s\?\s*\:\s*)(.*)$", &Equation)) {
Line := RegExReplace(Line, "im)^(.*\s*)\?\s*\:(\s*)(.*)$", '$1? "" :$3')
}
; Fixing ternary operations [var ? "1" : ] => [var ? "1" : ""]
if (RegExMatch(Line, "im)(^|\n)(.*\s\?.*\:\s*)(\)|$)", &Equation)) {
Line := RegExReplace(Line, "im)^(.*\s\?.*\:\s*)(\)|$)", '$1 ""$2')
}
; Fix quoted object properties [{"A": "B"}] => [{A: "B"}]
if InStr(Line, "{") and InStr(Line, '"') and InStr(Line, ":") {
maskStrings(&Line)
if InStr(Line, "{") and !InStr(Line, '"') and InStr(Line, ":") {
codeSplit := StrSplit(Line)
codeArray := [] ; Chunks of pre object, name, value, closing
tempCode := "" ; store chunk before pushing to codeArray
inObj := 0 ; tracks if we're in an obj
for , char in codeSplit {
tempCode .= char
if (char = "{") {
codeArray.Push(tempCode)
tempCode := ""
inObj++
} else if (char ~= ":|," and inObj) {
codeArray.Push(tempCode)
tempCode := ""
} else if (char = "}") {
codeArray.Push(tempCode)
tempCode := ""
inObj--
}
}
Line := ""
for , chunk in codeArray {
if RegExMatch(chunk, ":$") {
restoreStrings(&chunk)
chunk := RegExReplace(chunk, '"\s+\.\s+"')
chunk := StrReplace(chunk, '"')
}
Line .= chunk
}
}
restoreStrings(&Line)
}
If RegExMatch(Line, "\w+\.\(") {
maskStrings(&Line)
Line := RegExReplace(Line, "(\w+)\.\(", "$1.Call(")
restoreStrings(&Line)
}
LabelRedoCommandReplacing:
; -------------------------------------------------------------------------------
; Command replacing
;if (!InCont)
; To add commands to be checked for, modify the list at the top of this file
{
CommandMatch := 0
FirstDelim := RegExMatch(Line, "\w([ \t]*[, \t])", &Match) ; doesn't use \s to not consume line jumps
if (FirstDelim > 0)
{
Command := Trim(SubStr(Line, 1, FirstDelim))
Params := SubStr(Line, FirstDelim + StrLen(Match[1])+1)
} else
{
Command := Trim(SubStr(Line, 1))
Params := ""
}
; msgbox("Line=" Line "`nFirstDelim=" FirstDelim "`nCommand=" Command "`nParams=" Params)
; Now we format the parameters into their v2 equivilents
if (Command~="i)^#?[a-z]+$" && FindCommandDefinitions(Command, &v1, &v2))
{
SkipLine := ""
if (Params ~= "^[^`"]=")
SkipLine := Line
ListDelim := RegExMatch(v1, "[,\s]|$")
ListCommand := Trim(SubStr(v1, 1, ListDelim - 1))
if (ListCommand = Command)
{
CommandMatch := 1
same_line_action := false
ListParams := RTrim(SubStr(v1, ListDelim + 1))
ListParam := Array()
Param := Array() ; Parameters in expression form
Param.Extra := {} ; To attach helpful info that can be read by custom functions
Loop Parse, ListParams, ","
ListParam.Push(A_LoopField)
oParam := V1ParSplit(Params)
Loop oParam.Length
Param.Push(oParam[A_index])
; Checks for continuation section
;################################################################################
; 2024-08-06 AMB - UPDATED to fix #277
nContSect := 'i)^\s*\((?:\s*(?(?<=\s)(?!;)|(?<=\())(\bJoin\S*|[^\s)]+))*(?<!:)(?:\s+;.*)?$'
if (gOScriptStr.Length > gO_Index
; && (SubStr(Trim(gOScriptStr[gO_Index + 1]), 1, 1) = "("
&& (Trim(gOScriptStr[gO_Index + 1]) = "("
|| RegExMatch(Trim(gOScriptStr[gO_Index + 1]), nContSect))) {
ContSect := oParam[oParam.Length] "`r`n"
loop {
gO_Index++
if (gOScriptStr.Length < gO_Index) {
break
}
LineContSect := gOScriptStr[gO_Index]
FirstChar := SubStr(Trim(LineContSect), 1, 1)
if ((A_index = 1)
&& (FirstChar != "("
|| !RegExMatch(LineContSect, nContSect))) {
; no continuation section found
gO_Index--
}
;################################################################################
if (FirstChar == ")") {
; to simplify, we just add the comments to the back
if (RegExMatch(LineContSect, "(\s+`;.*)$", &EOLComment2))
{
EOLComment := EOLComment " " EOLComment2[1]
LineContSect := RegExReplace(LineContSect, "(\s+`;.*)$", "")
} else
EOLComment2 := ""
Params .= "`r`n" LineContSect
oParam2 := V1ParSplit(LineContSect)
Param[Param.Length] := ContSect oParam2[1]
Loop oParam2.Length - 1
Param.Push(oParam2[A_index + 1])
break
}
ContSect .= LineContSect "`r`n"
Params .= "`r`n" LineContSect
}
}
; save a copy of some data before formating
Param.Extra.OrigArr := Param.Clone()
Param.Extra.OrigStr := Params
; Params := StrReplace(Params, "``,", "ESCAPED_COMMª_PLA¢E_HOLDER") ; ugly hack
; Loop Parse, Params, ","
; {
; populate array with the params
; only trim preceeding spaces off each param if the param index is within the
; command's number of allowable params. otherwise, dont trim the spaces
; for ex: `IfEqual, x, h, e, l, l, o` should be `if (x = "h, e, l, l, o")`
; see ~10 lines below
; if (A_Index <= ListParam.Length)
; Param.Push(LTrim(A_LoopField)) ; trim leading spaces off each param
; else
; Param.Push(A_LoopField)
; }
; msgbox("Line:`n`n" Line "`n`nParam.Length=" Param.Length "`nListParam.Length=" ListParam.Length)
; if we detect TOO MANY PARAMS, could be for 2 reasons
if ((param_num_diff := Param.Length - ListParam.Length) > 0)
{
; msgbox("too many params")
extra_params := ""
Loop param_num_diff
extra_params .= "," . Param[ListParam.Length + A_Index]