Navigation
Guide That Contains This Content
[+] Expand All
[-] Collapse All

    SLAX Syntax Rules Overview

    SLAX syntax rules are similar to those of traditional programming languages like C and PERL. The following sections discuss general aspects of SLAX syntax rules:

    Code Blocks

    SLAX delimits blocks of code with curly braces. Code blocks, which may define the boundaries of an element, a hierarchy, or a segment of code, can be at the same level as or nested within other code blocks. Declarations defined within a particular code block have a scope that is limited to that block.

    The following example shows two blocks of code. Curly braces define the bounds of the match / block. The second block, containing the <op-script-results> element, is nested within the first.

    match / {
        <op-script-results> {
                <output> "Script summary:";
        }
    }

    Comments

    In SLAX, you can add comments anywhere in a script. Commenting a script increases readability for all users, including the author, who may need to return to a script long after it was originally written. It is recommended that you add comments throughout a script as you write it.

    In SLAX, you insert comments in the traditional C style, beginning with /* and ending with */. For example:

    /* This is a comment. */

    Multi-line comments follow the same format. In the following example, the additional "*" characters are added to the beginning of the lines for readability, but they are not required.

    /* Script Title
    * Author: Jane Doe
    * Last modified: 01/01/10
    * Summary of modifications: ...
    */

    The XSLT equivalent is:

    <!-- Script Title
    Author: Jane Doe
    Last modified: 01/01/10
    Summary of modifications: ...
    -->

    The following example inserts a comment into the script to remind the programmer that the output is sent to the console.

    match / {
        <op-script-results> {
            /* Output script summary to the console */
                <output> "Script summary: ...";
        }
    }

    Line Termination

    As with many traditional programming languages, SLAX statements are terminated with a semicolon.

    In the following example, the namespace declarations, import statement, and output element are all terminated with a semicolon. Lines that begin or end a block are not terminated with a semicolon.

    version 1.0;

    ns junos = "http://xml.juniper.net/junos/*/junos";
    ns xnm = "http://xml.juniper.net/xnm/1.1/xnm";
    ns jcs = "http://xml.juniper.net/junos/commit-scripts/1.0";
    import "../import/junos.xsl";
     
    match / {
        <op-script-results> {
            <output> "Script summary:";
               /* ... */
        }
    }

    Strings

    Strings are sequences of text characters. SLAX strings can be enclosed in either single quotes or double quotes. However, you must close the string with the same type of quote used to open the string. Strings can be concatenated together using the SLAX concatenation operation, which is the underscore (_).

    For example:

    match / {
        <op-script-results> {
            /* Output script summary to the console */
                <output> "Script" _ "summary: ...";
        }
    }

    Published: 2013-03-05