zcooler wrote:Didnt realize you could place the commas like that and still have a functional array.
Actually, the expression _can't_ span multiple lines. It's just that the continuation section (and certain expression operators) work as sort of a preprocessor macro: they 'merge' subsequent lines and create _one_ line. _Later on_, that line is parsed by Autohotkey in search for commands / expressions / other stuff. Note that
Join<space> means: join the lines of the continuation section with a space.
zcooler wrote:On the downside this array got huge and are taking most of the space in the config section. Im hesitant to use it at all, because of that reason.
Maybe
#include the config section or read the config section from a file. I think serializing AHK associative array objects is possible.
zcooler wrote:I was referring to Cocos example when using an array containing an object, then semicolons could not be used at all. The errormessage clearly stated that. Here is the example i meant. Im not sure if i got the code correct though, but it works as long as not using any semicolons:
Ah, ok, now I get it.
The error from the code above is:
Code: Select all
The leftmost character above is illegal in an expression.
Specifically: ;
The error occurs because by default, the continuation section _escapes_ all semicolons (so they could be i.e. treated as ~part of the literal text that the continuation section holds). But, if one uses the '
c option of the continuation section, the continuation section _won't_ escape all semicolons, so that those semicolons are treated as source code comments and are discarded by the parser.
I.e.:
//////edit: fixed examples:
before:
Code: Select all
obj :=
(Join
[
{
"MPEG2_ts": [".ts" . " " . "/p:""MPEG2 Transport Stream"""]
; , "MPEG2_mpg": [".mpg" . " " . "/p:""MPEG2 Program Stream"""]
}
]
)
after:
Code: Select all
obj := [ { "MPEG2_ts": [".ts" . " " . "/p:""MPEG2 Transport Stream"""]`; , "MPEG2_mpg": [".mpg" . " " . "/p:""MPEG2 Program Stream"""] } ]
The escaped
comma semicolon
`; is not a valid expression token (at that point), thus the error occurs.
before:
Code: Select all
obj :=
(c Join
[
{
"MPEG2_ts": [".ts" . " " . "/p:""MPEG2 Transport Stream"""]
; , "MPEG2_mpg": [".mpg" . " " . "/p:""MPEG2 Program Stream"""]
}
]
)
after:
Code: Select all
obj := [ { "MPEG2_ts": [".ts" . " " . "/p:""MPEG2 Transport Stream"""] } ]
Which is a correct expression.
- Note that if the c option is present in the continuation section, the order of operations is:
- remove commented out lines
- join remaining lines with the character sequence specified after Join
i.e.:
if the beginning state is:
Code: Select all
obj :=
(c Join
[
{
"MPEG2_ts": [".ts" . " " . "/p:""MPEG2 Transport Stream"""]
; , "MPEG2_mpg": [".mpg" . " " . "/p:""MPEG2 Program Stream"""]
}
]
)
then the effect of the continuation section is:
Code: Select all
obj := [ { "MPEG2_ts": [".ts" . " " . "/p:""MPEG2 Transport Stream"""] } ]
and is _not_:
Code: Select all
obj := [ { "MPEG2_ts": [".ts" . " " . "/p:""MPEG2 Transport Stream"""]
=> If I'd call lines of code that are _directly_ in the script file the 'raw lines' and lines adjoined with the continuation section 'adjoined lines', then, inside of the continuation section, if the c option is used, commented out _raw_ lines are removed (vs ~adjoined lines are commented out) (removal of commented lines works _before_ concatenation of lines, not after concatenation of lines).
The only thing that bothers me with this is: can I have a continuation section that _doesn't_ escape semicolons and at the same time those semicolons are later on part of the expression. The answer is ~:
sort of no, because if semicolons are not escaped, they are _always_? treated as comments, even if they are inside of double quotes:
Code: Select all
MsgBox, % "this is ; a text"
; error: Missing close-quote
Which I (along with Scite4Autohotkey syntax highlighter) didn't know.
So I guess the precedence of importance is like this: (from highest to lowest)
- semicolon
- double quote
- comma
I.e.
- the semicolon is always treated as a comment, even if the semicolon is inside of a double quote.
MsgBox, % "this is ; a text". Everything after the semicolon is a comment.
- If the comma is inside of double quotes, that comma is part of the literal string (and not i.e. a parameter separator).
MsgBox, % "this is , a text". The comma is part of the literal string.
Of course the rules probably change depending on the context, but for now, just for the record of it.