Created
April 11, 2012 01:56
-
-
Save nimdahk/2356313 to your computer and use it in GitHub Desktop.
Convert AutoIT Switch statements to AHK
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var = | |
( | |
Switch $me | |
Case "a" | |
MsgBox() | |
case 2 to 3 | |
Die() | |
case 4 to 5, 9 to 10, 15, 17 to 20 | |
Switch $you | |
case 14, 90, 100 to 1000 | |
wtf() | |
case else | |
ftw() | |
EndSwitch | |
Case else | |
e() | |
EndSwitch | |
) | |
Switch := 0 | |
Loop Parse, var, `n, `r | |
{ | |
If RegExMatch(A_LoopField, "mi`a)^(\s*)Switch(\s*.*)$", $) | |
out .= $1 "Switch" . ++Switch . " := " $2 | |
else if RegExMatch(A_LoopField, "mi`a)^(\s*)Case(.*)$", $) | |
{ | |
case%Switch%++ | |
if ( Trim($2) = "else" ) | |
{ | |
out .= $1 "else{`r`n" | |
continue | |
} | |
out .= $1 (Case%Switch% > 1 ? "}else " : "" ) . "if " | |
SwitchN := "Switch" Switch | |
Loop Parse, $2, `, | |
{ | |
if A_Index > 1 | |
out .= " or " | |
if RegExMatch(A_LoopField, "i)(.*)\s*To\s*(.*)") | |
out .= RegExReplace(A_LoopField, "i)(.*)\s*To\s*(.*)" | |
, "($1 <= " SwitchN " and " SwitchN " <= $2)") | |
else if RegExMatch(A_LoopField, "i)^(?!\sTo\s)(.*)$") | |
out .= RegExReplace(A_LoopField, "i)^(?!\sTo\s)(.*)$" | |
, "($1 = " SwitchN ")") | |
} | |
out .= "{" | |
} | |
else if RegExMatch(A_LoopField, "mi`a)^(\s*)EndSwitch(.*)", $) | |
{ | |
out .= $1 "}" $2 | |
Switch-- | |
} | |
else | |
out .= A_LoopField | |
out .= "`r`n" | |
} | |
StringTrimRight, out, out, 2 | |
MsgBox % out |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment