[AHK v2] Missing Ending "%"

Report problems with documented functionality
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

[AHK v2] Missing Ending "%"

14 Oct 2013, 06:23

In current ahk v2 alpha a UDF called using command syntax errors if first parameter is an expression.

Code: Select all

MsgBox % 1?1:0 ; works
m % 1?1:0      ; does not work
m(p){
}
lexikos
Posts: 9780
Joined: 30 Sep 2013, 04:07
Contact:

Re: [AHK v2] Missing Ending "%"

15 Oct 2013, 17:17

m % 1+1 does not produce an error, therefore you are mistaken. ;)

The problem is that the parser permits expressions like a ? b : c by doing a simple search for '?' and ':'. Since both appear in your example and 'm' is not a predefined action name, the line is treated as an expression instead of a command-call. I'm not sure how to fix it without breaking a ? b : c.
lexikos
Posts: 9780
Joined: 30 Sep 2013, 04:07
Contact:

Re: [AHK v2] Missing Ending "%"

16 Oct 2013, 02:54

I think that there's simply no way to allow both a ? b : c and a_cmd <any text> without making up complicated rules of the sort v2 is meant to abolish. Instead, I think it best to remove the special rule that allows standalone ternary expressions, and instead rely on the rule that any line beginning with ( and containing ) is an expression. For instance, a ? b : c would call the user-defined command named 'a' (or would produce a load-time error), while (a) ? b : c would function as it does now; as a ternary expression.

This doesn't apply to a.b ?... or f() ?..., which are always expressions regardless of the ternary operator.
guest3456
Posts: 3477
Joined: 09 Oct 2013, 10:31

Re: [AHK v2] Missing Ending "%"

16 Oct 2013, 15:37

what about requiring the comma after the command name?

lexikos
Posts: 9780
Joined: 30 Sep 2013, 04:07
Contact:

Re: [AHK v2] Missing Ending "%"

16 Oct 2013, 17:20

That would allow a_cmd,<any text>, not a_cmd <any text>. It would add an obscure rule for when the comma can be omitted. A user should not need to learn about ternary to understand why (for example) their custom MsgBox function doesn't work when they try to display a question and answer.

Code: Select all

MyMsgBox %Question%? Answer: 42.
This is currently misinterpreted as ternary.
Zelio
Posts: 278
Joined: 30 Sep 2013, 00:45
Location: France

Re: [AHK v2] Missing Ending "%"

16 Oct 2013, 18:09

"what about requiring the comma after the command name?"
I prefer this idea, Why the comma can be omitted ? I am not a fan of markup language but...
<onnewline>command<,> *<,>*<,>* <endline>
<anywhere>function<(> *<,>*<,>* <)><anywhere>
But a lot of users don't use comma and start with % for expression, however can be good to be strict... MsgBox, % "anything"
lexikos
Posts: 9780
Joined: 30 Sep 2013, 04:07
Contact:

Re: [AHK v2] Missing Ending "%"

16 Oct 2013, 21:54

I think one of us might be misinterpreting guest3456's suggestion. I took it (in the context of this thread) as meaning "require a comma when '?' and ':' are present, if it is to be interpreted as a command rather than a ternary expression".

I am not in favour of requiring the comma in all cases. I see the comma as a delimiter between parameters, and have always disliked that it is required between the command name and parameter in some cases.

It can be good to be strict, but I think that goes against the nature of the command syntax. It can be better to be convenient and readable.

It is better to write MsgBox("anything") than MsgBox, % "anything".
guest3456
Posts: 3477
Joined: 09 Oct 2013, 10:31

Re: [AHK v2] Missing Ending "%"

17 Oct 2013, 01:02

my suggestion was to always require the comma after any command name

and a resulting byproduct of that change would (could?) solve the ternary problem in this thread

i've never liked the flexibility of having it optional. but thats just personal preference. i always explicitly put it in my code. different strokes. when i first learned AHK, "commands" were an obscure syntax construct to me. i pretty much just had to convert all function thinking into command syntax. instead of "function name, open parenthesis, param list" i thought of it as "command name, comma, paramlist, check docs incase return value is first param"

was just throwing it out there. with v2 i will likely never use commands again anyway

HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: [AHK v2] Missing Ending "%"

17 Oct 2013, 04:32

I think flexibility is the point, so we should keep it :)

I think this should be solved the way lexikos suggested.
One line ternary is not used widely I think and not many scripts will be broken and you most likely will receive the right error message. Also fix is very simple, just wrap in (expr ? 0 : 1).
When we force to use , for commands, much more script would need to be changed.
guest3456
Posts: 3477
Joined: 09 Oct 2013, 10:31

Re: [AHK v2] Missing Ending "%"

17 Oct 2013, 13:16

HotKeyIt wrote:I think flexibility is the point, so we should keep it :)

I think this should be solved the way lexikos suggested.
One line ternary is not used widely I think and not many scripts will be broken and you most likely will receive the right error message. Also fix is very simple, just wrap in (expr ? 0 : 1).
When we force to use , for commands, much more script would need to be changed.
indeed very true

lexikos
Posts: 9780
Joined: 30 Sep 2013, 04:07
Contact:

Re: [AHK v2] Missing Ending "%"

18 Oct 2013, 04:21

This has topic brought to my attention a more general inconsistency between built-in commands and other commands. Standalone actions which start with a word are currently handled in this order:
  • Function-calls which end the line with ')' (due to the way function definitions are handled)
  • Assignments, dot (x.y, x.y := z, x.y(), etc.)
  • Built-in commands
  • Post-increment/decrement (i++)
  • Ternary
  • Function calls, calls to object properties (x[]), expressions that begin the line with '('
  • Anything that could be a user-defined command (since some functions may be defined later in the script)
I think that if it looks like a command, it should be a handled as a command -- I'll be changing user-defined (and undefined) commands to be interpreted the same as built-in commands.

Ternary is recognized in two separate cases (after handling built-in commands):
  1. The first non-whitespace character after the name is '?'.
  2. The first non-whitespace character after the name is an "expression" character, and the line contains '?' with ':' somewhere to the right of it.
The second case is a very rough check, but in v1 that's fine since the only alternative is to treat the line as an error. I am currently considering two options:
  1. Make #1 above the same precedence as assignment, so cmd ? ... is always an expression, but make #2 lower precedence than commands (since it's a rough check).
  2. Make ternary lower precedence than commands, so cmd ? ... is always a command.
For both options, cmd,? is always a command and w+x ? y : z is always an expression (because there's no space after w). Also, any line beginning with ( and containing ) is an expression.


There are some cases which are currently handled incorrectly in both versions of AutoHotkey:

Code: Select all

msgboz, (This is incorrectly assumed to be a function call, so the typo is not reported)
msgobx, [As above]
foo,++  ; v1 says: "+=" requires that parameter #2 be non-blank.
foo,?   ; Treated as an expression. v2 complains about the missing ':'.
Basically, the comma is inappropriately ignored.
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: [AHK v2] Missing Ending "%"

18 Oct 2013, 05:40

Make ternary lower precedence than commands, so cmd ? ... is always a command.
+1

Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 24 guests