From eec0868d01783fd8bfc21e268bedf6d6c740fc42 Mon Sep 17 00:00:00 2001 From: Banaanae <83927639+Banaanae@users.noreply.github.com> Date: Tue, 13 Aug 2024 18:16:18 +1000 Subject: [PATCH] Fix brace issue (#282) * fix brace issue fix #87 * fix if in preline --- ConvertFuncs.ahk | 31 ++++++++++++++++++- .../Flow of Control/if_issue87_ex1.ah1 | 6 ++++ .../Flow of Control/if_issue87_ex1.ah2 | 8 +++++ .../Flow of Control/if_issue87_ex2.ah1 | 7 +++++ .../Flow of Control/if_issue87_ex2.ah2 | 9 ++++++ .../Flow of Control/if_issue87_ex3.ah1 | 6 ++++ .../Flow of Control/if_issue87_ex3.ah2 | 8 +++++ 7 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 tests/Test_Folder/Flow of Control/if_issue87_ex1.ah1 create mode 100644 tests/Test_Folder/Flow of Control/if_issue87_ex1.ah2 create mode 100644 tests/Test_Folder/Flow of Control/if_issue87_ex2.ah1 create mode 100644 tests/Test_Folder/Flow of Control/if_issue87_ex2.ah2 create mode 100644 tests/Test_Folder/Flow of Control/if_issue87_ex3.ah1 create mode 100644 tests/Test_Folder/Flow of Control/if_issue87_ex3.ah2 diff --git a/ConvertFuncs.ahk b/ConvertFuncs.ahk index 432a4456..fbe3ddc5 100644 --- a/ConvertFuncs.ahk +++ b/ConvertFuncs.ahk @@ -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 != "") { @@ -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] @@ -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 != "") { diff --git a/tests/Test_Folder/Flow of Control/if_issue87_ex1.ah1 b/tests/Test_Folder/Flow of Control/if_issue87_ex1.ah1 new file mode 100644 index 00000000..f420a136 --- /dev/null +++ b/tests/Test_Folder/Flow of Control/if_issue87_ex1.ah1 @@ -0,0 +1,6 @@ +var := 1 + +if var +try MsgBox yes +else +MsgBox no \ No newline at end of file diff --git a/tests/Test_Folder/Flow of Control/if_issue87_ex1.ah2 b/tests/Test_Folder/Flow of Control/if_issue87_ex1.ah2 new file mode 100644 index 00000000..e1e5d689 --- /dev/null +++ b/tests/Test_Folder/Flow of Control/if_issue87_ex1.ah2 @@ -0,0 +1,8 @@ +var := 1 + +if var +{ +try MsgBox("yes") +} +else +MsgBox("no") \ No newline at end of file diff --git a/tests/Test_Folder/Flow of Control/if_issue87_ex2.ah1 b/tests/Test_Folder/Flow of Control/if_issue87_ex2.ah1 new file mode 100644 index 00000000..008b54be --- /dev/null +++ b/tests/Test_Folder/Flow of Control/if_issue87_ex2.ah1 @@ -0,0 +1,7 @@ +var := 1 + +if var +;comment talking about if +try MsgBox yes +else +MsgBox no \ No newline at end of file diff --git a/tests/Test_Folder/Flow of Control/if_issue87_ex2.ah2 b/tests/Test_Folder/Flow of Control/if_issue87_ex2.ah2 new file mode 100644 index 00000000..2bab15f4 --- /dev/null +++ b/tests/Test_Folder/Flow of Control/if_issue87_ex2.ah2 @@ -0,0 +1,9 @@ +var := 1 + +if var +;comment talking about if +{ +try MsgBox("yes") +} +else +MsgBox("no") \ No newline at end of file diff --git a/tests/Test_Folder/Flow of Control/if_issue87_ex3.ah1 b/tests/Test_Folder/Flow of Control/if_issue87_ex3.ah1 new file mode 100644 index 00000000..3c09a02c --- /dev/null +++ b/tests/Test_Folder/Flow of Control/if_issue87_ex3.ah1 @@ -0,0 +1,6 @@ +var = a + +if var=a +try MsgBox, Yes +else +MsgBox, No \ No newline at end of file diff --git a/tests/Test_Folder/Flow of Control/if_issue87_ex3.ah2 b/tests/Test_Folder/Flow of Control/if_issue87_ex3.ah2 new file mode 100644 index 00000000..4b433b8d --- /dev/null +++ b/tests/Test_Folder/Flow of Control/if_issue87_ex3.ah2 @@ -0,0 +1,8 @@ +var := "a" + +if (var = "a") +{ +try MsgBox("Yes") +} +else +MsgBox("No") \ No newline at end of file