Skip to content

Instantly share code, notes, and snippets.

@nimdahk
Created April 11, 2012 01:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nimdahk/2356313 to your computer and use it in GitHub Desktop.
Save nimdahk/2356313 to your computer and use it in GitHub Desktop.
Convert AutoIT Switch statements to AHK
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