I did a bit more investigation to determine where one may use end-of-line comments. The crucial factor seems to eliminating ambiguity, so that the parser that validates scripting content can distinguish arguments of the script element from end-of-line comments. Below is a summary of my findings.
Script statements with one parameter
Script statements that take a single parameter are the simplest case. There is no possibility that the parser will confuse an end-of-line comment with an optional parameter, because the statement takes no optional parameters.
:SET &VAR1# = "ABC123" ! This is a comment.
Script statements with one or more optional parameters
Script statements that take optional parameters introduce the possibility of ambiguity. The :PRINT
https://docs.automic.com/documentation/webhelp/english/ALL/components/DOCU/LATEST/AWA%20Guides/help.htm#AE_AWA_Source/Script/ucaadu.htmstatement usually takes just one argument, but it can also take an optional second argument. So if one tries to save a script containing this line:
:PRINT "Variable 1: &VAR1#" ! This is another comment.
this error message will appear:
Error: U04006586 Error found in object
'UC0.MAL.SCRIPT_WITH_END_OF_LINE_COMMENTS.SCRI(Process)', line '2'.
('U01001311 The instruction is missing a comma before parameter '2'.')
The parser is designed in such a way that it tries to help the user write valid scripts. To this end, it tries to identify instances of statements where an optional parameter has been specified without the comma separating it from previous parameters. The parser is not currently clever enough to realize that when such extraneous text begins with an exclamation point, it is intended to be an end-of-line comment. For this reason, if one wishes to use end-of-line comments with script statements that have optional parameters, one must specify all of the optional parameters, even if one specifies null values for these parameters.
Adding a blank second argument (,""
) to the :PRINT
statement above eliminates the ambiguity.
:PRINT "Variable 1: &VAR1#","" !
This is another comment.
One may not use end-of-line comments on lines containing script statements with omitted optional parameters.
Script functions with one or more optional parameters
However, one may omit optional parameters in script functions and still use end-of-line comments. Script functions are script elements that return a result. The arguments of script function are specified inside parentheses. E.g, the SUBSTR
script function takes either two or three parameters. One can omit the third parameter, and still specify an end-of-line comment.
:SET &VAR2# = SUBSTR(&VAR1#,3) ! Yet another comment.
I assume that the reason this works is because the closing parenthesis clearly marks the end of the function. This allows the parser to easily distinguish parameters of the function from end-of-line comment text.