Operators And Tokens

A table of all supported operators and tokens

Table of Contents

Syntax

Murex supports both expressions and statements. You can use the interchangeably with your code and the Murex parser will decide whether to run that code as an expression or statement.

Expressions

Expressions are patterns formed like equations (eg $val = 1 + 2).

Strings must be quoted in expressions.

Statements

Statements are traditional shell command calls (eg command parameters...).

Quoting strings is optional in statements.

Not all operators are supported in statements.

Order Of Operations

Expressions and statements are split by pipes and terminators. Each statement and expression is executed from left to right, with the statement or expression parsed by the following rules of operation

Order of operations: 1. expression or statement discovery 2. sub-shells / sub-expressions 3. multiplication / division (expressions only) 4. addition / subtraction (expressions only) 5. comparisons, eg greater than 6. logical and (sub-expressions only) 7. logical or (sub-expressions only) 8. elvis (expressions only) 9. assign (expressions only) 10. left to right

Expression Or Statement Discovery

First a command is read as an expression. Because the rules of parsing expressions are stricter than statements, everything is assumed to be an expression unless the expression parser fails, which then it is assumed to be a statement.

Operators And Tokens

Terminology

Example: left operator right

Modifiers

All modifiers replace the left, operator and right with the returned value of the modifier.

All returns will be num data type (or their original type if strict types is enabled).

Modifiers are only supported in expressions.

Operator Name Operation
* Multiplication Multiply left by right
/ Divide Divide left by right
+ Addition Add left with right
- Subtraction Subtract left by right

Read more: * Data types: num, int, float * Strict types config: strict types * Operators: +, -, *, /

Comparators

All comparators replace the left, operator and right with the returned value of the comparator.

All returns will be bool data type, either true or false.

Comparators are only supported in expressions.

Operator Name Operation
> Greater Than true if left is greater than right
>= Greater Or Equal To true if left is greater or equal to right
< Less Than true if left is less than right
<= Less Or Equal To true if left is less or equal to right
== Equal To true if left is equal to right
!= Not Equal To false if left is equal to right
~~ Like true if left string is like right string
!! Not Like false if left string is like right string
=~ Matches Regexp true if left matches regexp pattern on right
!~ Does Not Match Regexp false if left matches regexp pattern on right

Read more: * Data types: bool

Assignment

Assignment returns true if successful.

Assignment is only supported in expressions.

Operator Name Operation
= Assign (overwrite) Assign right to left
:= Assign (retain) EXPERIMENTAL
<~ Assign Or Merge Merge right (array / object) into left
+= Assign And Add Add right to left and assign to left
-= Assign And Subtract Subtract right from left and assign to left
*= Assign And Multiply Multiply right with left and assign to left
/= Assign And Divide Divide right with left and assign to left

Read more: * Data types: bool * Operators: =, <~, +=, -=, =, =

Conditionals

Conditionals replace left, operator and right with the value defined in operation.

These conditionals are only supported in expressions.

Operator Name Operation
?? Null Coalescence Returns left if not null, otherwise right
?: Elvis Returns left if truthy, otherwise right

Read more: * Operators: ??, ?:

Sigils

Sigils are special prefixes that provide hints to the parser.

Sigils are supported in both expressions and statements.

Token Name Operation
$ Scalar Expand value as a string
@ Array Expand value as an array
~ Home Expand value as the persons home directory
% Builder Create an array, map or nestable string

Constants

Constants are supported in both expressions and statements. However null, true, false and number will all be interpreted as strings in statements.

Token Name Operation
null Null null (null / nil / void) type
true True bool (boolean) true
false False bool (boolean) false
number Number num (numeric) value
'string' String Literal str (string) literal value
"string" Infix String str (string) value, supports escaping & infixing
%(string) String Builder Creates a nestable str (string)
%[array] Array Builder Creates a json (JSON) array (list)
%{map} Object Builder Creates a json (JSON) object (map / dictionary)

Read more: * Operators: ‘string’, “string”, %(string), %[array], %{map}

Sub-shells

Sub-shells are a way of inlining expressions or statements into an existing expression or statement. Because of this they are supported in both.

Syntax Name Operation
command( parameters… ) C-Style Functions Inline a command as a function
${command parameters…} Sub-shell (scalar) Inline a command line as a string
@{command parameters…} Sub-shell (array) expand a command line as an array
(expression) Sub-expression Inline an expression (statement)
(expression) Sub-expression Order of evaluation (expression)

Read more: * C-style functions, sub-shells, sub-expressions

Boolean Operations

Boolean operators behave like pipes.

They are supported in both expressions and statements.

Operator Name Operation
&& And Evaluates right if left is truthy
\|\| Or Evaluates right if left is falsy

Pipes

Pipes always flow from left to right.

They are supported in both expressions and statements.

Operator Name Operation
\| POSIX Pipe POSIX compatibility
-> Arrow Pipe Context aware pipe
=> Generic Pipe Convert stdout to * (generic) then pipe
\|> Truncate File Write stdout to file, overwriting contents
>> Append File Write stdout to file, appending contents

Terminators

“LF” refers to the life feed character, which is a new line.

Token Name Operation
; Semi-Colon End of statement or expression (optional)
LF Line Feed End of statement or expression (new line)

Escape Codes

Any character can be escaped via \ to signal it isn’t a token. However some characters have special meanings when escaped.

“LF” refers to the life feed character, which is a new line.

Token Name Operation
\s Space Same as a space character
\t Tab Same as a tab character
\r Carriage Return Carriage Return (CR) sometimes precedes LF
\n Line Feed Line Feed (LF), typically a new line
\LF Escaped Line Feed Statement continues on next line

See Also


This document was generated from gen/user-guide/operators-tokens_doc.yaml.

This site's content is rebuilt automatically from murex's source code after each merge to the master branch. Downloadable murex binaries are also built with the website.

Last built on Thu Aug 15 14:38:34 UTC 2024 against commit 50ed9d650ed9d6df391240d3c2c02e623636e508dfcdad1.

Current version is 6.2.4000 which has been verified against tests cases.