diff --git a/RELEASES.md b/RELEASES.md index f144c309..6f9e4ed9 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -20,7 +20,7 @@ Breaking changes * New reserved symbols: `++`, `--`, `..`, `...`. * Callback signature for custom syntax implementation function is changed to allow for more flexibility. * Default call stack depth for `debug` builds is reduced to 12 (from 16). -* Precedence for `~` and `%` is raised. +* Precedence for `~` is raised, while `in` is moved below logic comparison operators. New features ------------ diff --git a/doc/src/engine/custom-op.md b/doc/src/engine/custom-op.md index bc8ff83f..fa2b1487 100644 --- a/doc/src/engine/custom-op.md +++ b/doc/src/engine/custom-op.md @@ -84,7 +84,11 @@ Operator Precedence All operators in Rhai has a _precedence_ indicating how tightly they bind. -The following _precedence table_ show the built-in precedence of standard Rhai operators: +A higher precedence binds more tightly than a lower precedence, so `*` and `/` binds before `+` and `-` etc. + +When registering a custom operator, the operator's precedence must also be provided. + +The following _precedence table_ shows the built-in precedence of standard Rhai operators: | Category | Operators | Precedence (0-255) | | ------------------- | :-------------------------------------------------------------------------------------: | :----------------: | @@ -92,15 +96,11 @@ The following _precedence table_ show the built-in precedence of standard Rhai o | Logic and bit masks | \|\|, \|, `^` | 30 | | Logic and bit masks | `&`, `&&` | 60 | | Comparisons | `==`, `!=` | 90 | -| Comparisons | `>`, `>=`, `<`, `<=` | 110 | -| | `in` | 130 | +| | `in` | 110 | +| Comparisons | `>`, `>=`, `<`, `<=` | 130 | | Arithmetic | `+`, `-` | 150 | | Arithmetic | `*`, `/`, `%` | 180 | | Arithmetic | `~` | 190 | | Bit-shifts | `<<`, `>>` | 210 | | Object | `.` _(binds to right)_ | 240 | -| _Others_ | | 0 | - -A higher precedence binds more tightly than a lower precedence, so `*` and `/` binds before `+` and `-` etc. - -When registering a custom operator, the operator's precedence must also be provided. +| Unary operators | unary `+`, `-`, `!` _(binds to right)_ | 255 | diff --git a/src/token.rs b/src/token.rs index eb2d63f3..d4e04c02 100644 --- a/src/token.rs +++ b/src/token.rs @@ -617,9 +617,9 @@ impl Token { EqualsTo | NotEqualsTo => 90, - LessThan | LessThanEqualsTo | GreaterThan | GreaterThanEqualsTo => 110, + In => 110, - In => 130, + LessThan | LessThanEqualsTo | GreaterThan | GreaterThanEqualsTo => 10, Plus | Minus => 150,