Files
Twig/doc/operators_precedence.rst
Fabien Potencier b8e6b314b3 Merge branch '3.x' into 4.x
* 3.x:
  fix documentation typos for singular filter arguments
  Add getOperatorTokens() to ExpressionParserInterface to separate operator token registration from parser identity
  Ensure filters/attributes aren't mistaken for operators
2026-02-25 09:40:35 +01:00

103 lines
12 KiB
ReStructuredText

+------------+------------------+---------+---------------+-------------------------------------------------------------------+
| Precedence | Operator | Type | Associativity | Description |
+============+==================+=========+===============+===================================================================+
| 512 | ``...`` | prefix | n/a | Spread operator |
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
| | ``(`` | infix | Left | Twig function call |
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
| | ``.``, ``?.`` | | | Get an attribute on a variable |
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
| | ``[`` | | | Array access |
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
| 500 | ``-`` | prefix | n/a | |
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
| | ``+`` | | | |
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
| 300 | ``|`` | infix | Left | Twig filter call |
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
| 250 | ``=>`` | infix | Left | Arrow function (x => expr) |
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
| 200 | ``**`` | infix | Right | Exponentiation operator |
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
| 100 | ``is`` | infix | Left | Twig tests |
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
| | ``is not`` | | | Twig tests |
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
| 70 | ``not`` | prefix | n/a | |
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
| 60 | ``*`` | infix | Left | |
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
| | ``/`` | | | |
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
| | ``//`` | | | Floor division |
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
| | ``%`` | | | |
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
| 30 | ``+`` | infix | Left | |
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
| | ``-`` | | | |
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
| 27 | ``~`` | infix | Left | |
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
| 25 | ``..`` | infix | Left | |
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
| 20 | ``==`` | infix | Left | |
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
| | ``!=`` | | | |
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
| | ``<=>`` | | | |
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
| | ``<`` | | | |
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
| | ``>`` | | | |
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
| | ``>=`` | | | |
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
| | ``<=`` | | | |
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
| | ``not in`` | | | |
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
| | ``in`` | | | |
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
| | ``matches`` | | | |
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
| | ``starts with`` | | | |
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
| | ``ends with`` | | | |
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
| | ``has some`` | | | |
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
| | ``has every`` | | | |
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
| | ``===`` | | | |
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
| | ``!==`` | | | |
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
| 18 | ``b-and`` | infix | Left | |
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
| 17 | ``b-xor`` | infix | Left | |
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
| 16 | ``b-or`` | infix | Left | |
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
| 15 | ``and`` | infix | Left | |
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
| 12 | ``xor`` | infix | Left | |
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
| 10 | ``or`` | infix | Left | |
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
| 5 | ``?:``, ``? :`` | infix | Right | Elvis operator (a ?: b) |
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
| | ``??`` | | | Null coalescing operator (a ?? b) |
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
| 0 | ``(`` | prefix | n/a | Explicit group expression (a) |
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
| | ``?`` | infix | Left | Conditional operator (a ? b : c) |
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
| | ``=`` | | Right | Assignment operator |
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
| | ``literal`` | prefix | n/a | A literal value (boolean, string, number, sequence, mapping, ...) |
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
When a precedence will change in the next major version, the new precedence is indicated by the arrow ``=>``.