Automic Workload Automation

  • 1.  Comments at the end of script lines

    Posted Aug 24, 2017 09:53 AM

    I recently came across an object with comments at the end of script lines. E.g.,

    :SET &VAR1# = "ABC123" ! This is a comment.
    :PRINT "Variable 1: &VAR1#"

    No error occurs when I save this script. It executes without error too.

    2017-08-24 15:33:09 - U00020408 Variable 1: ABC123

    The documentation indicates that this type of comment is not allowed. Here is the relevant passage from the “Comment Lines” section of the Script Structure documentation page (emphasis mine):

    Each line starting with the exclamation mark character "!", is a  comment. These lines are not considered as processing steps and skipped  during script execution...If the exclamation mark character is used within a line, however, this line is not considered a comment.

    Are end-of-line comments allowed, or is the documentation in error? If this type of comment is allowed, in which set of circumstances it it permitted?




  • 2.  Comments at the end of script lines

    Posted Aug 24, 2017 10:16 AM
    That sentence in the documentation page does not say it is not allowed to have in-line comments. It only says that the line (as in "the whole line") is not considered a comment. One can, therefore, infer that part of the line after the exclamation mark might be considered to be a comment, but not the whole line. Your tests seem to confirm this interpretation.
    I never used in-line comments before, but I agree with you that the documentation is not clear, though. It should say that both in-line and full-line comments are allowed.



  • 3.  Comments at the end of script lines

    Posted Aug 24, 2017 10:17 AM
    Stumbled over that some weeks ago...

    Seems that not all commands accept commands on end of line - see PRINT

    gd3jx7ksomn8.jpghttps://us.v-cdn.net/5019921/uploads/editor/01/gd3jx7ksomn8.jpg" width="595">

    so I kept on the safe side - one line per comment line :-)


  • 4.  Comments at the end of script lines

    Posted Aug 24, 2017 10:43 AM
    Wolfgang Brueckler wrote:
    Stumbled over that some weeks ago...
    Seems that not all commands accept commands on end of line - see PRINT
    gd3jx7ksomn8.jpghttps://us.v-cdn.net/5019921/uploads/editor/01/gd3jx7ksomn8.jpg" width="595">
    so I kept on the safe side - one line per comment line :-)
    Add a blank second argument (,"") to the :PRINT statement and it will work.


  • 5.  Comments at the end of script lines

    Posted Aug 24, 2017 01:24 PM
    THX

    Michael A. Lowry



    Now its clear the PRINT command waits for 2 arguments...


  • 6.  Comments at the end of script lines

    Posted Aug 24, 2017 01:36 PM
    Note too that the syntax coloring fails to correctly color comments at the ends of lines.


  • 7.  Comments at the end of script lines

    Posted Aug 24, 2017 01:42 PM
    Yes I still recognized that.

    But syntax coloring fails in some more cases during work...
    So I did not really took care about that.

    I still use a seperate line for comments...


  • 8.  Comments at the end of script lines

    Posted Aug 25, 2017 04:19 AM

    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 :PRINThttps://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.