Skip to content

Commit 05c0020

Browse files
committed
Merge branch '7.0' into 7.1
* 7.0: [ExpressionLanguage] Add operators precedence documentation
2 parents b7719c1 + 8f8def7 commit 05c0020

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

reference/formats/expression_language.rst

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,41 @@ Other Operators
431431
* ``?.`` (:ref:`null-safe operator <component-expression-null-safe-operator>`)
432432
* ``??`` (:ref:`null-coalescing operator <component-expression-null-coalescing-operator>`)
433433

434+
Operators Precedence
435+
~~~~~~~~~~~~~~~~~~~~
436+
437+
Operator precedence determines the order in which operations are processed in an
438+
expression. For example, the result of the expression ``1 + 2 * 4`` is ``9``
439+
and not ``12`` because the multiplication operator (``*``) takes precedence over
440+
the addition operator (``+``).
441+
442+
To avoid ambiguities (or to alter the default order of operations) add
443+
parentheses in your expressions (e.g. ``(1 + 2) * 4`` or ``1 + (2 * 4)``.
444+
445+
The following table summarizes the operators and their associativity from the
446+
**highest to the lowest precedence**:
447+
448+
======================================================= =============
449+
Operators associativity
450+
======================================================= =============
451+
``-``, ``+`` (unary operators that add the number sign) none
452+
``**`` right
453+
``*``, ``/``, ``%`` left
454+
``not``, ``!`` none
455+
``~`` left
456+
``+``, ``-`` left
457+
``..`` left
458+
``==``, ``===``, ``!=``, ``!==``, left
459+
``<``, ``>``, ``>=``, ``<=``,
460+
``not in``, ``in``, ``contains``,
461+
``starts with``, ``ends with``, ``matches``
462+
``&`` left
463+
``^`` left
464+
``|`` left
465+
``and``, ``&&`` left
466+
``or``, ``||`` left
467+
======================================================= =============
468+
434469
Built-in Objects and Variables
435470
------------------------------
436471

0 commit comments

Comments
 (0)