Operators And Tokens

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. immutable merge 6. comparisons, eg greater than (expressions only) 7. logical and (sub-expressions only) 8. logical or (sub-expressions only) 9. elvis (expressions only) 10. assign (expressions only) 11. 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: +, -, *, /

Immutable Merge

Returns the result of merging right into left.

immutable merge does not modify the contents of either left nor right.

The direction of the arrow indicates that the result returned is a new value rather than an updated assignment.

Left can be a statement or expression, whereas right can only be an expression. However you can still use a sub-shell as part of, or the entirety, of, that expression.

Operator Name Operation
~> Immutable Merge Returns merged value of right into left

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 null 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
++ Add one to variable Adds one to right and reassigns
-- Subtract one from var Subtracts one from right and reassigns

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
{ code } Code Block str (string) value, surrounded by curly braces
%( 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)
[{ code block }] Lambda Run operations across lists / maps

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 Wed Sep 18 21:18:57 UTC 2024 against commit c037883c03788357164e9846c84d9f777251495d9452a8e.

Current version is 6.3.4225 (develop) which has been verified against tests cases.