Skip to content

Commit

Permalink
Fix brace issue (#282)
Browse files Browse the repository at this point in the history
* fix brace issue

fix #87

* fix if in preline
  • Loading branch information
Banaanae authored Aug 13, 2024
1 parent ad7f3ec commit eec0868
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 1 deletion.
31 changes: 30 additions & 1 deletion ConvertFuncs.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,11 @@ _convertLines(ScriptString, finalize:=!gUseMasking) ; 2024-06-26 RENAMED to ac
; 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]*|[$~!^#+]*,)::.*$") && (FirstTwo != "::")) {
LineNoHotkey := RegExReplace(Line, "(^\s*).+::(.*$)", "$2")
if (LineNoHotkey != "") {
Expand Down Expand Up @@ -699,6 +704,30 @@ _convertLines(ScriptString, finalize:=!gUseMasking) ; 2024-06-26 RENAMED to ac
PreLine .= Equation[1]
Line := Equation[3]
}
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]
Expand Down Expand Up @@ -987,7 +1016,7 @@ _convertLines(ScriptString, finalize:=!gUseMasking) ; 2024-06-26 RENAMED to ac
}
}

Line := PreLine Line
Line := PreLine Line PostLine

; Add back LinePrefix if exists
if (LinePrefix != "") {
Expand Down
6 changes: 6 additions & 0 deletions tests/Test_Folder/Flow of Control/if_issue87_ex1.ah1
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var := 1

if var
try MsgBox yes
else
MsgBox no
8 changes: 8 additions & 0 deletions tests/Test_Folder/Flow of Control/if_issue87_ex1.ah2
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
var := 1

if var
{
try MsgBox("yes")
}
else
MsgBox("no")
7 changes: 7 additions & 0 deletions tests/Test_Folder/Flow of Control/if_issue87_ex2.ah1
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
var := 1

if var
;comment talking about if
try MsgBox yes
else
MsgBox no
9 changes: 9 additions & 0 deletions tests/Test_Folder/Flow of Control/if_issue87_ex2.ah2
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var := 1

if var
;comment talking about if
{
try MsgBox("yes")
}
else
MsgBox("no")
6 changes: 6 additions & 0 deletions tests/Test_Folder/Flow of Control/if_issue87_ex3.ah1
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var = a

if var=a
try MsgBox, Yes
else
MsgBox, No
8 changes: 8 additions & 0 deletions tests/Test_Folder/Flow of Control/if_issue87_ex3.ah2
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
var := "a"

if (var = "a")
{
try MsgBox("Yes")
}
else
MsgBox("No")

0 comments on commit eec0868

Please sign in to comment.