Is a comma after the #Include directive correct?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
john_c
Posts: 493
Joined: 05 May 2017, 13:19

Is a comma after the #Include directive correct?

22 Feb 2021, 05:35

If you look into the AutoHotkey.tmLanguage file of the AutHotkey package for Sublime Text, you will see that regular expressions to match #Include and #IncludeAgain directives are different from the regular expressions to match other directives.

(https://github.com/ahkscript/SublimeAutoHotkey/blob/master/AutoHotkey.tmLanguage)

Code: Select all

^\s*(#)(?:persistent|singleinstance),*?\s*?(.*?)\s*(;.*)?$ // I have edited this line to make it shorter, there were more directives

^\s*(#)(?:includeagain|include)\s+(.*?)\s*(;.*)?$
Why, according to the second regex, there should be no comma after the directive?

Here is the exact "where" and "when" this change was introduced:

https://github.com/ahkscript/SublimeAut ... b723d35L91
gregster
Posts: 9113
Joined: 30 Sep 2013, 06:48

Re: Is a comma after the #Include directive correct?

22 Feb 2021, 06:34

The docs don't list a comma for its syntax (but afaik it gets ignored, when used).

Since commas for statements are often optional, and only necessary in certain cases with multiple parameters (if optional parameter in the front get left out), #include is probably exempt from using a comma as it always has only one parameter - and thus there can be no ambiguities. A comma would serve no additional purpose.

But why they treat other directives (with one or no parameters and also showing no commas in the docs) differently, would probably be a question for the Sublime language file maintainers.
john_c
Posts: 493
Joined: 05 May 2017, 13:19

Re: Is a comma after the #Include directive correct?

22 Feb 2021, 07:10

gregster wrote:
22 Feb 2021, 06:34
Since commas for statements are often optional, and only necessary in certain cases with multiple parameters (if optional parameter in the front get left out), #include is probably exempt from using a comma as it always has only one parameter - and thus there can be no ambiguities. A comma would serve no additional purpose.

But why they treat other directives (with one or no parameters and also showing no commas in the docs) differently, would probably be a question for the Sublime language file maintainers.
Yes. For example, the following lines are considered correct, in spite of the fact that there cannot be more than one parameter, and therefore there is no reason to use a comma other than for a reason of personal preference.

Code: Select all

FileDelete, C:\temp files\*.tmp
#ClipboardTimeout, 2000
#If, WinActive("ahk_class Notepad") or WinActive(MyWindowTitle)
gregster
Posts: 9113
Joined: 30 Sep 2013, 06:48

Re: Is a comma after the #Include directive correct?

22 Feb 2021, 07:20

Well, AHK v1 is not really famous for exuberant consistency. :D

It even seems that a comma after #include is necessary in this special case:
assume you have an include-file called , test.ahk - the filename starting with a literal comma
then you need an additional comma to make it work:

Code: Select all

#include, , test.ahk
Otherwise, if you just use #include , test.ahk it will just look for file called test.ahk instead and throw an error because it can't be found.

escaping with ` or using quotes won't work (which is actually mentioned in the docs).
john_c
Posts: 493
Joined: 05 May 2017, 13:19

Re: Is a comma after the #Include directive correct?

22 Feb 2021, 09:00

Thanks, this is a good example.

This is a different topic, but I think it would be much better to have Microsoft Language Server support for AutoHotkey instead of maintaining regex-based highlighting schemes for every particular editor. Easier so maintain, more reliable, provides more options (for example, you can rename all of the instances of a single-letter variable without breaking anything. This tool understands semantics), already supported in Sublime Text, Vim, Emacs, IDEA, probably some other editors and IDEs. Even Unix people say this is amazing, 21st century tool.
User avatar
rommmcek
Posts: 1480
Joined: 15 Aug 2014, 15:18

Re: Is a comma after the #Include directive correct?

22 Feb 2021, 15:48

Don't know most of the syntax by heart, in doubt I test...
Consider these too:

Code: Select all

for, i, j in arr ;o.k.
    ;...
while, a=1 ;o.k.
    ;...
if, a=1 ;Error
    ;...
Global, a ;Error
Local, a ;Error
Static, a ;Error
gregster wrote:
22 Feb 2021, 07:20
AHK v1 is not really famous for exuberant consistency.
However I love AutoHotkey!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: apeironn, Google [Bot], madensuyu1, peter_ahk and 337 guests