Talking about the fixed code:
ON *:TEXT:whatever:#channel: {
IF (1 == 1) { Command1 | Command2 } ; | TestCommand3 }
AlwaysCommand
}
You cannot comment code reliably with the ';' if it's not starting the line. You can check
this thread for more informations about how ; can in fact be used to comment only a single statement out of multiple statement separated by a |, but is has a quirk and you cannot comment out the last statement if it ends with a } or the } is parsed incorrectly, but if no } are involved on the line, you can comment a single statement, even the last :
alias test {
echo -ag ok | echo -ag ok1 | ;echo -ag ok2
}
Will only display ok and ok1, it's also worth noting that the else statement does not have this problem and you can always comment out the last statement of a single line else statement with multiple statements in it as is the case in the above link.
You also still have one extra } in this code, making 'alwayscommand' outside on the on text event because spaced out } cannot be commented out if ; isn't starting the line.
Focusing only on the line "
IF (1 == 1) { Command1 | Command2 } ; | TestCommand3
", what's happening there is that } in itself acts as a statement separator:
//if (1 == 1) { echo -ag ok | echo -ag ok1 } echo -ag ok2
is equivalent to
//if (1 == 1) { echo -ag ok | echo -ag ok1 | echo -ag ok2 }
If you change the condition to 1 == 2 for example, 'ok2' is not echoed
It's known that } act as a statement separator, same as |, and you don't need prior { } involvement to see this:
//echo -ag ok } echo -ag ok1
is equivalent to
//echo -ag ok | echo -ag ok1
So then ';' is seen as starting a statement but you see, the quirk with ; and commenting out single statement is that it correctly works stopping at a | but not a }, so this is the same as
IF (1 == 1) { Command1 | Command2 | ; | TestCommand3 }
Where you just have an empty commented out statement, and /testcommand3 is executed 'normally'
Although the problem is as simple as "; starting a statement which is not starting a line but is the last statement in a line doesn't stop at } correctly", given Khaled's answer it's likely that fixing it would require more work than just adding that logic once somewhere. But of course I would like to be able to comment out single statement like that so I wouldn't mind a fix.
I wouldn't recommend anyone trying to comment out single statement out of multiple statements separated by | on a single line or trying to commentate anything with ; if it's not starting the line anyway because of all of these, but if you're aware of them, you can actually workaround them. For example you can solve the issue reported in the mentioned url by adding a fake last empty statement, just by adding a spaced out pipe character, which works for your case as well, coming from this code:
ON *:TEXT:whatever:#channel: {
IF (1 == 1) { Command1 | Command2 | TestCommand3 }
AlwaysCommand
}
and trying to get testcommand3 not to be executed without changing much in the code, your best bet is
ON *:TEXT:whatever:#channel: {
IF (1 == 1) { Command1 | Command2 | ;TestCommand3 | }
AlwaysCommand
}
But trying to use ; when it's not starting a line and when it's not starting a statement properly either (properly aka after the } in your original example isn't proper) is just not possible.