Hello!
Is there a way to verify that the syntax in my .AHK file is correct without actually executing it? I tried the compiler and it just seems to spit out an .exe even if it's not a valid .AHK file.
Thanks in advance for your time!
Stand-alone syntax validator?
-
- Posts: 3
- Joined: 23 Jul 2015, 12:07
- Facebook: alexdresko
- Google: alexdresko
- GitHub: alexdresko
- lifeweaver
- Posts: 144
- Joined: 10 May 2014, 05:57
- GitHub: lifeweaver
- Location: OH
Re: Stand-alone syntax validator?
Hi alexdresko,
You might merely add #Persistent and a return at the top so it gets interpreted but doesn't actually do anything, or perhaps try out #warn.
You might merely add #Persistent and a return at the top so it gets interpreted but doesn't actually do anything, or perhaps try out #warn.
Re: Stand-alone syntax validator?
If you use /ErrorStdOut, any load-time error that occurs will be written to StdErr. If you use /iLib, the script won't be executed even if there are no errors.
/iLib normally creates a file listing any stdlib auto-includes that your script uses. Using nul prevents this. (nul is a feature of the file system, and can be used with many other programs.)
If there are no load-time errors, the output is empty.
Code: Select all
FileAppend MsgBx`n, ~badscript.ahk
MsgBox % ScriptErrors("~badscript.ahk")
FileDelete ~badscript.ahk
ScriptErrors(Script)
{
return ComObjCreate("WScript.Shell")
.Exec("AutoHotkey.exe /iLib nul /ErrorStdOut """ Script """")
.StdErr.ReadAll()
}
If there are no load-time errors, the output is empty.
Re: Stand-alone syntax validator?
This is a very nice minimal example, thanks. I have noticed that it somehow won't work with Unicode. Is that a limitation of Windows exec, or am I doing something wrong? I'm trying to find a work-around, but I have so far failed:lexikos wrote: ↑31 Dec 2015, 17:44If you use /ErrorStdOut, any load-time error that occurs will be written to StdErr. If you use /iLib, the script won't be executed even if there are no errors.
...
/iLib normally creates a file listing any stdlib auto-includes that your script uses. Using nul prevents this. (nul is a feature of the file system, and can be used with many other programs.)
If there are no load-time errors, the output is empty.
Code: Select all
FileAppend ¾ ž é ō Û`n, ~badscript.ahk, UTF-8 ; Result: ¾ ? é ? Û
; FileAppend ¾ ž é ō Û`n, ~badscript.ahk, UTF-16 ; Result: ¾ ? é ? Û
; FileAppend € é Û`n, ~badscript.ahk, UTF-8 ; Result: � é �
FileRead, FileContent, ~badscript.ahk
Msgbox % "This is the correct content: " FileContent ; Result: ¾ ž é ō Û (correct)
ErrorString := ScriptErrors("~badscript.ahk")
ErrorString := RegExReplace(ErrorString, "si)^.*Specifically:(.*)$", "$1")
MsgBox % "This is the output from the ScriptErrors functions: " ErrorString ; Result: ¾ ? é ? Û
FileDelete ~badscript.ahk
; The below is a file specifically saved as UTF-8 with BOM, containing ¾ ž é ō Û
; MsgBox % ScriptErrors("D:\Dropbox\Autohotkey\unicode_test_script.ahk") ; Result: ¾ ? é ? Û
ScriptErrors(Script){
return ComObjCreate("WScript.Shell")
.Exec("AutoHotkey.exe /iLib nul /ErrorStdOut """ Script """")
; .Exec("AutoHotkey.exe /iLib nul /ErrorStdOut /CP65001 """ Script """") ; Makes no difference
.StdErr.ReadAll()
}
The saved file (see commented-out code above) I used was this:
Code: Select all
¾ ž é ō Û
Last edited by Cerberus on 09 Apr 2019, 08:38, edited 1 time in total.
Re: Stand-alone syntax validator?
Hi Cerberus,
I ran your code and got the following output:
I am running AHK v1.1.30.01 U32.
I hope this helps.
- iPhilip
I ran your code and got the following output:
Code: Select all
C:\~badscript.ahk (1) : ==> This line does not contain a recognized action.
Specifically: ¾ ž é Š�
I hope this helps.
- iPhilip
Windows 7 Pro (64 bit) - AutoHotkey v1.1+ (Unicode 32-bit)
Re: Stand-alone syntax validator?
Hey, thanks for testing! So you got yet another error! Now we have two completely different outputs, yours and mine, but both incorrect. Did the first message box display the correct symbols for you?
You're running 32-bit Autohotkey; I'm running 64-bit. We're running the same version v1.1.30.01. I'm on Windows 10 Pro.
This is far beyond my skill, alas. Perhaps someone will be able to make something of this in the future...
Re: Stand-alone syntax validator?
FYI. I ran it with U64 and got the same result.
Windows 7 Pro (64 bit) - AutoHotkey v1.1+ (Unicode 32-bit)
-
- Posts: 1362
- Joined: 30 Sep 2013, 22:25
Re: Stand-alone syntax validator?
I ran on AHK v1.1.30.01 U64 with Windows 10 Home. USA system with no international stuff going on.Cerberus wrote: ↑08 Apr 2019, 19:11Hey, thanks for testing! So you got yet another error! Now we have two completely different outputs, yours and mine, but both incorrect. Did the first message box display the correct symbols for you?
You're running 32-bit Autohotkey; I'm running 64-bit. We're running the same version v1.1.30.01. I'm on Windows 10 Pro.
This is far beyond my skill, alas. Perhaps someone will be able to make something of this in the future...
It ran fine with the expected error identificaion.
FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
[Function] Timer - Create and Manage Timers
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
[Function] Timer - Create and Manage Timers
Re: Stand-alone syntax validator?
Thanks for testing! Gosh, how odd. The second message box gives ¾ ? é ? Û for me. My system is set to American English, using the American standard keyboard as well. I use Dutch regional settings, but changing those to American didn't make any difference. My Windows is a fairly recent install, Windows 10 Pro. Everything else works perfectly as well, and I have never come across any Unicode issues outside Autohotkey. I have no idea what else to look for. Might it have something to do with unusual file locations, or something? Or some setting in Windows that I don't remember changing? Or could it be because I'm a few Windows updates behind?FanaticGuru wrote: ↑08 Apr 2019, 20:12I ran on AHK v1.1.30.01 U64 with Windows 10 Home. USA system with no international stuff going on.
It ran fine with the expected error identificaion.
FG
P.S. When I compile the script, I get an error when I run it, telling me Exec cannot be found or something. Is that normal?
Re: Stand-alone syntax validator?
may I ask what this means in ahk (in your opinion) :
¾ ž é ō Û
Hubert
¾ ž é ō Û
Hubert
Re: Stand-alone syntax validator?
It means nothing; it's just a test for Unicode characters. I am using this in a linter: when you type text in an editor, it automatically shows you errors. The problem is that it won't show the error correctly if there are certain Unicode characters in the error message. The above is the shortest way to cause such an error message to be generated. A realistic example would be Amount := "€ 100. This gives an error message, as the closing quotation marks have been omitted. But the error message is not displayed correctly (will show Amount := "? 100).
-
- Posts: 1362
- Joined: 30 Sep 2013, 22:25
Re: Stand-alone syntax validator?
I did not read the thread correctly. I was running the OP without problem.Cerberus wrote: ↑08 Apr 2019, 21:15Thanks for testing! Gosh, how odd. The second message box gives ¾ ? é ? Û for me. My system is set to American English, using the American standard keyboard as well. I use Dutch regional settings, but changing those to American didn't make any difference. My Windows is a fairly recent install, Windows 10 Pro. Everything else works perfectly as well, and I have never come across any Unicode issues outside Autohotkey. I have no idea what else to look for. Might it have something to do with unusual file locations, or something? Or some setting in Windows that I don't remember changing? Or could it be because I'm a few Windows updates behind?FanaticGuru wrote: ↑08 Apr 2019, 20:12I ran on AHK v1.1.30.01 U64 with Windows 10 Home. USA system with no international stuff going on.
It ran fine with the expected error identificaion.
FG
P.S. When I compile the script, I get an error when I run it, telling me Exec cannot be found or something. Is that normal?
When I run your code, I get the same unexpected result of ¾ ? é ? Û.
I have no idea what is causing this problem. I tried encoding with: UTF-16 Big Endian, UTF-16 Little Endian, UTF-8 with BOM, and UTF-8. All the encoding options my editor had and none gave the correct result.
FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
[Function] Timer - Create and Manage Timers
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
[Function] Timer - Create and Manage Timers
Re: Stand-alone syntax validator?
Thank you very much for retesting! So it's not my system, after all. I tried the same things you did. I suspect it might be a Windows issue, but I don't know who might be able to tell us more.FanaticGuru wrote: ↑09 Apr 2019, 12:01I did not read the thread correctly. I was running the OP without problem.
When I run your code, I get the same unexpected result of ¾ ? é ? Û.
I have no idea what is causing this problem. I tried encoding with: UTF-16 Big Endian, UTF-16 Little Endian, UTF-8 with BOM, and UTF-8. All the encoding options my editor had and none gave the correct result.
FG