Инструменты пользователя

Инструменты сайта


en:autorun:documentation:syntax_type

Types of syntax

Since version 3.0, Autorun has the ability to fully use conditions and expressions with «functional syntax» or «functional notation» in addition to the classic «command syntax» or «command notation». In the future, the help will use the terms «functional notation» and «command notation».

Command Syntax

In earlier versions of Autorun, until the conditions were introduced, only one kind of syntax was used — command. This kind of syntax is widely used to pass parameters to an application via command line, and usually includes a list of parameters, one after the other, and switches, which can be placed in any order (in Autorun, the switches must come before the parameters). The example below will launch the 64-bit version of Total Commander in a minimized state:

ShellExec /SW_MINIMIZE "%COMMANDER_PATH%\Totalcmd64.exe"

This kind of syntax uses spaces to separate the parameters. If the parameter text contains a space — then the parameter is enclosed in quotation marks. Also, the parameter text can contain Autorun variables or environment variables, in the example above %COMMANDER_PATH% — is an environment variable containing the path to Total Commander.

The advantages of this syntax include the ease of writing and processing parameters, the ability to implement complex logic in a relatively compact notation.

But there are also disadvantages. With a large number of switches and parameters, it becomes more difficult to intuitively understand what exactly a given combination of them does. If the command must return a value, this notation becomes bulky and inconvenient. It is also almost impossible to use commands directly in expressions (particularly in conditions).

:i: An important feature of writing commands in this syntax: computed strings in parameters are executed after entering into command. In function syntax, expressions in parameters are executed before entering into command. This currently only matters for commands that react to events (ControlSetMouseAction, SetHotkeyAction, SetMessageAction), as they execute other commands.

Functional Syntax

The functional syntax is designed to solve the shortcomings of the command syntax. This notation (with variations) is widely used in most programming languages. Example:

p = StrPos("abcdefgh", "cd")
# p = 3

The result of the execution of function equal 3 — the position of the substring will be written to the «p» variable.

The functional syntax is convenient for use in expressions: in assignment operations, conditions, function definitions. For example:

if StrPos("abcdefgh", "cd") = 3 then MsgBox("Yes")

In this code, if the substring position is 3, then the MsgBox command is called, showing a message.

Unlike the command syntax, you cannot use variables directly in the text here (except for commands for which it is explicitly indicated that they expand variables). The variable is in the expression separately, what needs to be done with its value is determined by the adjacent operators:

a = 1
b = a + 1 # --> b = 2, addition
b = a & 1 # --> b = "11", concatenation (merging of two strings)

Functional Syntax Interpretation

Historically, at first the strings in expressions were «non-strict», i.e. it was allowed to write strings without enclosing quotes (similar to command syntax). Unfortunately, the desire to maintain full compatibility at that stage led to problems later on and hindered further development. Therefore, when writing the current version, it was decided to change the default expression interpretation settings, but leave the option to use the previous version as an option.

The interpretation is determined by directive LegacyExpressions. If this set in script, the old interpretation will be used.

The differences between the current and the old implementation are as follows:

Actual:

  1. All strings must be quoted (using any of the two quote types)
  2. Variables in expressions are used without % characters, but can be enclosed in them.
  3. An error is thrown when a missing variable is used in an expression.
  4. No ambiguities in expressions.

Previous:

  1. Strings can be quoted (either of the two types) or unquoted, but only if the string does not contain spaces or separators.
  2. Variables must be enclosed in %%.
  3. If the variable does not exist, the variable name itself is returned, no errors are thrown.
  4. Ambiguities in expressions are possible, which can lead to difficult-to-diagnose errors.

Although in general scripts will work in both versions, it is strongly recommended to use the current version, as it eliminates possible ambiguities in the interpretation of strings and produces error messages with variables, which makes debugging easier.

Some examples of how two interpretations work:

# Actual
a = "zxc"                # -- ok
c = %a%                  # -- ok, assign value to a
c = a                    # -- ok, assign value to a
b = StrLen("qwerty")     # -- ok
b = StrLen(%a%)          # -- ok
b = StrLen(a)            # -- ok
b = StrLen(a & "qwerty") # -- ok
 
# Old
a = "zxc asd"               # -- ok
a = zxc                     # -- ok
c = %a%                     # -- ok, assign value to a
c = a                       # -- ok, assign the string "a"
b = StrLen(qwerty)          # -- ok
b = StrLen("qwerty")        # -- ok
b = StrLen(%a%)             # -- ok
b = StrLen(a)               # -- ok, will return "1", string length "a"
b = StrLen("qwerty asdf")   # -- quotation marks are required, because space
b = StrLen("qw(er)ty,asdf") # -- quotation marks are required, because there are delimiters ",()" in the string
b = StrLen(%a% & qwerty)    # -- ok
 
# Ambiguity example:
While %h% > 0
  h = %h% - 1
Wend
# In the absence of a declared variable h, will be immediate 
# exit from the loop, because will returned "%h%" - a string,
# which is not converting to a number, therefore = 0
en/autorun/documentation/syntax_type.txt · Последнее изменение: 2022/09/16 22:57 — loopback

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki