LavishScript:Syntax

From Lavish Software Wiki
Jump to: navigation, search

This page describes the syntax for any given command, including "data" sequences. Script format can be found in Script Development.

Simple Command

A Simple Command is made up of a Command Name, and any Parameters given to it. Parameters are optional.

Possible forms are as follows

  • <Command Name>
  • <Command Name> [Parameters]

Examples

LSVersion

In this example, "LSVersion" is the Command Name

DeclareVariable MyBool bool local false

In this example, "DeclareVariable" is the Command Name, and "MyBool bool local false" are the parameters

Command Name

A command name is a single word. The only "special" character that has any effect in a command name is [, which will be used as an Index, for use with data methods. Quotes do not have an effect on spaces, as they would with parameters or indices, but will be stripped if they surround the single word. Data are not processed as part of the command name.

If the command name is found to contain a :, the command name is assumed to be that of a data method. In such cases, any parameters following the command are ignored, and the command is considered successful, whether or not the method is successfully processed.

If the command name is not assumed to be a method, it will first be checked for a matching alias, and then for an actual command. Aliases must match completely, though actual commands can be shortened and will resolve to the first matching command alphabetically.

Parameters

Parameters are words separated by spaces. If an individual parameter must itself include a space, or certain special characters should not be interpreted as part of a complex command, double quotes (") should be used around the parameter. Data are valid in any parameter, and will be processed (potentially becoming multiple parameters) unless the command name indicates a command that instructs otherwise (in which case the data will be treated as a single word). If data are processed, they will be replaced with the "return" (also referred to as "To String") value of the final resulting object.

Examples

Test OneParameter Two Parameters "One Parameter"

In this example, the Test command is executed with exactly four parameters. The fourth parameter contains a space. The quotes are removed before the command sees them. See Escape Sequences for how to pass quotes to a command. The following are the resulting parameters.

  1. OneParameter
  2. Two
  3. Parameters
  4. One Parameter

Data Sequences

Data sequences begin with ${ and end with }. Inside this, possible forms are as follows:

  • <Object>
  • <Object>.<Member>
  • <Object>:<Method>
  • <Object>(cast)
  • <Object>[Index]

These forms are recursive. Every Member, Method, or cast results in an Object for which the form can be continued. Indices have special rules, as described below.

To prevent a data sequence from reducing upon execution of the command, use the escape character to escape the initial ${, such as:

echo \${System.OS}

Indices

Indices begin with [ and end with ]. Inside this, each dimension is described and separated by a comma. If a comma or ] must be used within a single dimension, double quotes (") are used around the dimension. Dimensions are interpreted as dimensions for arrays, or individual parameters where applicable. Data are processed in indices (possibly becoming multiple dimensions if the result contains a comma), unless used in a parameter to a command that instructs otherwise (in which case the data will be processed as a term in a single dimension). If data are processed, they will be reduced to text. Indices are not limited to numerical values, they are the same as parameters, but delimited by commas.

Complex Command

Complex commands are commands and their parameters, with the allowance of command lists.

A Command List is described as follows:

  • <Simple Command>;<Simple Command>

Command lists are interpreted from left to right

Examples

Execute two commands
echo one line;echo two lines
Execute one command which uses a command list as a single parameter
bind example ctrl+alt+x "echo one line;echo two lines"

Escape Sequences

Escape sequences are character sequences that have their own special meaning.

Escape sequences consist of a backslash (\) and a following character:

  • \<character>

Recognized characters and their meanings are as follows:

  • a: Character 7, the ASCII beep
  • e: Character 27, the ESC character (useful for terminal color/control/etc sequences)
  • n: Character 10, Line feed
  • r: Character 13, Carriage return
  • t: Character 9, Horizontal tab
  • xFF: Where "FF" is exactly two hexadecimal digits, the sequence is replaced by the character identified by this value
All other characters following the escape character are treated as that character, and the escape character is removed. For example, \" is a quote, and \\ is a backslash.

Often times it is necessary to prevent characters from having the special meanings as described in other sections. For example, one way to use a comma inside a dimension in an Index is to enclose the entire dimension in quotes. However, escape sequences can also be used for this purpose. By escaping a comma, it will not be treated as a dimension separator in an index.

Examples

Test OneParameter Two Parameters "One \"Parameter\""

In this example, the Test command is executed with exactly four parameters. The fourth parameter contains a space. The unescaped quotes are removed before the command sees them. However, the escaped quotes will become unescaped quotes when sent to the function, resulting in the following parameters

  1. OneParameter
  2. Two
  3. Parameters
  4. One "Parameter"