[a136] OTB style fail to parsed in Switch block Topic is solved

Report problems with documented functionality
User avatar
aseiot
Posts: 79
Joined: 05 Mar 2017, 04:25

[a136] OTB style fail to parsed in Switch block

Post by aseiot » 23 May 2021, 20:12

Demonstrated as follow

Code: Select all

Switch 1
{
Case 1:
	if true {
    	a:=1
	}
Default:                                   ;Error:  Unexpected "Case"
    a:=1
}
Work if we change to

Code: Select all

Switch 1
{
Case 1:
	if true
	{
    	a:=1
	}
Default:
    a:=1
}
quaritexa
Posts: 32
Joined: 09 Nov 2017, 21:03

Re: [a136] OTB style fail to parsed in Switch block

Post by quaritexa » 23 May 2021, 23:27

This works too:

Code: Select all

switch 1 {
  case 1:
    if (true) {
      a:=1
    }
  default:
    a:=1
}
quaritexa
Posts: 32
Joined: 09 Nov 2017, 21:03

Re: [a136] OTB style fail to parsed in Switch block

Post by quaritexa » 23 May 2021, 23:29

Also this:

Code: Select all

blah(args*) {
  hotkey args*
}
returns error:
Line Text: hotkey args* }
Error: Unexpected "}"

The program will exit.
lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: [a136] OTB style fail to parsed in Switch block

Post by lexikos » 24 May 2021, 03:37

Code: Select all

Case 1:
  if true {
    a:=1
  }
Default:
is erroneously interpreted as

Code: Select all

Case 1: if true { a:=1 }
    Default:
due to line continuation, whereas inserting a line break before { changes it to

Code: Select all

Case 1: if true
  {
    a:=1
  }
Default:
and adding parentheses changes it to

Code: Select all

Case 1: if (true) {
    a:=1
  }
Default:
since ) { looks like function definition OTB and isn't valid within an expression.


x y* is intentionally line continuation. I chose to prioritize more flexibility for line continuation over function call statements. The new related documentation is:
a line that ends with an expression operator is automatically merged with the line below it.
Source: Scripts - Definition & Usage | AutoHotkey v2
Function call statements cannot be variadic; that is, the parameter list must be enclosed in parentheses (or brackets for a property).
Source: Functions - Definition & Usage | AutoHotkey v2
When optional parameters are omitted, any commas at the end of the parameter list must also be omitted to prevent line continuation.
Function call statements cannot be variadic, although they can pass a fixed number of parameters to a variadic function.
Source: Scripting Language | AutoHotkey v2
Aside from changing the variadic syntax (which I avoid), I don't think there's any other way to resolve the ambiguity between a variadic function call statement and multiplication spanning multiple lines. The rule is effectively that *) or *] denotes a variadic call, and not just *. This was already implied, and is actually how it was implemented, but function call statements effectively insert the parentheses at load time (after line continuation).
There must not be any non-whitespace characters between the asterisk (*) and the symbol which ends the parameter list.
Source: Functions - Definition & Usage | AutoHotkey v2
I wasn't 100% sure about the change but figured there would be some problems that would only be revealed if I try it.
User avatar
aseiot
Posts: 79
Joined: 05 Mar 2017, 04:25

Re: [a136] OTB style fail to parsed in Switch block

Post by aseiot » 24 May 2021, 06:55

Thanks for the instructive explanation, as always!
quaritexa
Posts: 32
Joined: 09 Nov 2017, 21:03

Re: [a136] OTB style fail to parsed in Switch block

Post by quaritexa » 24 May 2021, 18:18

Another case:

Code: Select all

switch StrLower(arg) {
  case "input":
    try {
      DetectHiddenWindows(1)
    }
  case "main":
    return 1
}
Error
Unexpected "Case"
lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: [a136] OTB style fail to parsed in Switch block  Topic is solved

Post by lexikos » 17 Jul 2021, 22:46

Fixed in v2.0-a137.
Post Reply

Return to “Bug Reports”