diff --git a/crates/dax/README.md b/crates/dax/README.md index 9accf32c3..b896914bd 100644 --- a/crates/dax/README.md +++ b/crates/dax/README.md @@ -201,19 +201,20 @@ right, except `^`: | Level | Operators | Associativity | | --- | --- | --- | -| 1 | grouping `()`, function calls, `IN` | — (`IN` is an infix operator) | +| 1 | grouping `()`, function calls | — | | 2 | `^` | right | | 3 | unary `+`, `-` | prefix | | 4 | `*`, `/` | left | | 5 | binary `+`, `-` | left | | 6 | `&` | left | -| 7 | `=`, `==`, `<>`, `<`, `>`, `<=`, `>=` | left | +| 7 | `=`, `==`, `<>`, `<`, `>`, `<=`, `>=`, `IN` | left | | 8 | `NOT` | prefix | | 9 | `&&` | left | | 10 | `\|\|` | left | `=` coerces types at evaluation time; `==` is strict equality. This crate only records which -operator was written. `IN` takes a list (`expr IN { v1, v2 }`) or a table expression +operator was written. `IN` is a comparison at the same level as `=`, so `1 + 2 IN { 3 }` parses as +`(1 + 2) IN { 3 }`, and it takes a list (`expr IN { v1, v2 }`) or a table expression (`expr IN VALUES(T[Col])`). Excel evaluates `2^3^2` as `512` (`2^(3^2)`), so `^` is right-associative even though the generic diff --git a/crates/dax/src/ast.rs b/crates/dax/src/ast.rs index e5cb33daa..fa9377eb2 100644 --- a/crates/dax/src/ast.rs +++ b/crates/dax/src/ast.rs @@ -214,8 +214,8 @@ impl BinaryOp { } /// Binding power, higher binds tighter. The values encode the ten precedence levels - /// from DAX Guide: parentheses/calls/`IN`, `^`, unary sign, `* /`, `+ -`, `&`, - /// comparisons, `NOT`, `&&`, `||`. + /// from the operator table: parentheses/calls, `^`, unary sign, `* /`, `+ -`, `&`, + /// comparisons (including `IN`), `NOT`, `&&`, `||`. pub const fn precedence(self) -> u8 { match self { BinaryOp::Pow => 90, diff --git a/crates/dax/src/parser.rs b/crates/dax/src/parser.rs index da2e85712..3b386aede 100644 --- a/crates/dax/src/parser.rs +++ b/crates/dax/src/parser.rs @@ -1,9 +1,9 @@ //! Pratt parser: tokens → [`Expr`] / [`Query`]. //! -//! Binding powers encode the DAX operator table from (tighter -//! binds first): parentheses, function calls and `IN`; `^`; unary `+`/`-`; `*`/`/`; binary -//! `+`/`-`; `&`; comparisons; `NOT`; `&&`; `||`. All operators are left-associative except -//! `^`, which Excel evaluates right-associatively (`2^3^2` is 512). +//! Binding powers encode the operator table (tighter binds first): parentheses and function +//! calls; `^`; unary `+`/`-`; `*`/`/`; binary `+`/`-`; `&`; comparisons, which include `IN`; `NOT`; +//! `&&`; `||`. All operators are left-associative except `^`, which Excel evaluates +//! right-associatively (`2^3^2` is 512). use crate::ast::{ Axis, AxisGroup, AxisKind, AxisOrderItem, BinaryOp, Call, ColumnDef, Define, Definition, Evaluate, Expr, ExprKind, FunctionDef, FunctionParam,