AHK v1 to AHK v2 converter (initial work)

Discuss the future of the AutoHotkey language
User avatar
jeeswg
Posts: 2189
Joined: 19 Dec 2016, 01:58
Location: UK

AHK v1 to AHK v2 converter (initial work)

06 Sep 2017, 20:11

This will become a script that converts AHK v1.1 code to AHK v2 code.

For the time being, it will be a script that converts AHK v1.1 code to AHK v1.1 code that is more forwards compatible, i.e. more AHK v2-ready.

I will eventually make it able to convert from AHK v1.1 to AHK v2, however I need AHK v2 to be more finalised before it's worth finishing/publishing stage 2.

Note: Currently this handles:
- var = string -> var := "string"
- var = num -> var := num
It can also identify where continuation sections begin/end.
I will add in further 'var = ' to 'var := ' support, and also various conversions such as StringReplace to StrReplace.

I would suggest that you compare any before/after code with a utility such as WinMerge to confirm that any changes were the right ones, and I would recommend backing up your original code.

I may also add in some code, which can be turned on/off to:
- confirm each line matches certain standards (including: ensure commands have/don't have commas between the command name and the first parameter)
- convert some parameters to force expression mode, e.g. 'Cmd, %var%' to 'Cmd, % var'
- clean up NumPut e.g. ensure 4 parameters
- clean up DllCall lines (this could be quite challenging)
- indent code (I finally got some working code for this yesterday, that correctly converted an entire script)

Some things may be trickier, and so I may provide no or limited support for them, e.g. converting StringSplit to StrSplit, or handling 'return' lines with multiple parameters, or handling the removal of SetFormat. [I will return with a list of the more difficult conversions that would need to be done manually.]

I may also provide support to convert code so that it can use my 'AHK v2 functions for AHK v1' library.

I may also provide support for converting existing functions to variant functions, e.g. SubStr lines to 'JEE_SubStr' lines, providing an AHK v2-style 'SubStr' in AHK v1. Perhaps I will call that particular function one of: 'AHKv2_SubStr' / 'Ahk2_SubStr' / 'SubStr2' / 'JEE_SubStr2', I'm not sure, although I tend to prefer that any nonstandard function have a prefix of some sort to avoid confusion with standard functions.

However, some of these things may present difficulties, so there may be limited modes that convert some matching lines (safer conversions), but that instead notify you of potential other matching lines (riskier conversions) (perhaps by appending comments to those lines).

Btw I've already done all the serious work for this, it's more getting it ready for public viewing that is the issue. Also, of course I need AHK v2 to be more finalised, I've already had to do a lot of 'unconverting' and major rewrites to conversion scripts as the AHK v2 specs have changed, so I've decided to put AHK v1 -> AHK v2 conversion on hold, and focus on AHK v1 command style to AHK v1 expression style, and related script checking and script tidying.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Helgef
Posts: 2223
Joined: 17 Jul 2016, 01:02
Contact:

Re: AHK v1 to AHK v2 converter (initial work)

07 Sep 2017, 02:07

Thanks for your effors jeeswg, I will test this. :thumbup:
@ guest3456, hello :wave: , is your converter up to date, I remember it was quite good, but there has been many changes since that thread was active.

Cheers.
guest3456
Posts: 2019
Joined: 09 Oct 2013, 10:31

Re: AHK v1 to AHK v2 converter (initial work)

07 Sep 2017, 08:45

Helgef wrote:@ guest3456, hello :wave: , is your converter up to date, I remember it was quite good, but there has been many changes since that thread was active.


not up to date unfortunately, but the framework should be solid to build upon and update, pull requests are welcome :)

User avatar
derz00
Posts: 244
Joined: 02 Feb 2016, 17:54

Re: AHK v1 to AHK v2 converter (initial work)

25 Sep 2017, 13:36

jeeswg wrote:

Code: [Select all] [Download] GeSHi © Codebox Plus


;JEE_WinMergeCompareStrings("BEFORE`r`n" vTextOrig, "AFTER`r`n" vOutput)



Mind sharing this function?

I ran the script on one of my scripts and it changed nothing. Any idea why? What exactly is it supposed to change?

guest3456 has GUI set up nice already. And his script saves the new code as A_ScriptName "_v2new.ahk"
either stumped or stunned
User avatar
jeeswg
Posts: 2189
Joined: 19 Dec 2016, 01:58
Location: UK

Re: AHK v1 to AHK v2 converter (initial work)

25 Sep 2017, 15:06

The script is currently very limited, see the first post, it just handles some 'var = value' lines. Hence 'initial work' in the thread title.

If rapid progress is made with the development of AHK v2, this will become a priority, otherwise, I will post some updates at some point.

Recently I've been working on some scripts that tidy instances of DllCall, and that identify where functions and their parameters start and end. I've also been investigating continuation sections as part of an automated indentation function. Plus I wrote the basis of a WinMerge alternative.

While I've been having a lot of success with parsing, I've recently discovered the problem of handling all notation to do with objects.

indent code (automated code indentation) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=37270

It's quite easy to parse instances of 'one line one function' / 'one line one command', and these are the bulk of conversion, I'll share some code fairly soon, but functions within functions, back-to-back commands, and multi-line functions/commands, that may include indentation, comments and the use of continuation sections are harder.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus


Return to “AutoHotkey v2 Development”

Who is online

Users browsing this forum: No registered users and 2 guests