| @@ -257,15 +257,15 @@ |
| 257 | 257 | // The `in`-RHS *test* form keeps its own `Interval` rule below (a unary test, not a |
| 258 | 258 | // value), reachable only after `in`, so the two never share an LR state. |
| 259 | 259 | RangeLit: Expr = { |
| 260 | | - "[" <lo:Sum> ".." <hi:Sum> <eo:IntervalEnd> => |
| 260 | + "[" <lo:Sum> ".." <hi:Endpoint> <eo:IntervalEnd> => |
| 261 | 261 | Expr::RangeLit(Interval { start_open: false, start: Box::new(lo), end: Box::new(hi), end_open: eo }), |
| 262 | | - "(" <lo:Sum> ".." <hi:Sum> <eo:IntervalEnd> => |
| 262 | + "(" <lo:Sum> ".." <hi:Endpoint> <eo:IntervalEnd> => |
| 263 | 263 | Expr::RangeLit(Interval { start_open: true, start: Box::new(lo), end: Box::new(hi), end_open: eo }), |
| 264 | 264 | // Reverse-open `]a..b]` ≡ `(a..b]`: an exclusive lower bound spelt with a leading |
| 265 | 265 | // `]`. The lexer retags that opener to `RBracketOpen` (a distinct terminal), so |
| 266 | 266 | // this shares no LR state with the `]` closer — same start-openness as the `(` |
| 267 | 267 | // form, the close bracket still chosen by `IntervalEnd`. |
| 268 | | - RBracketOpen <lo:Sum> ".." <hi:Sum> <eo:IntervalEnd> => |
| 268 | + RBracketOpen <lo:Sum> ".." <hi:Endpoint> <eo:IntervalEnd> => |
| 269 | 269 | Expr::RangeLit(Interval { start_open: true, start: Box::new(lo), end: Box::new(hi), end_open: eo }), |
| 270 | 270 | }; |
| 271 | 271 | |
| @@ -331,13 +331,13 @@ |
| 331 | 331 | InRhs: Vec<UnaryTest> = { |
| 332 | 332 | <op:CmpOp> <e:Sum> => vec![UnaryTest::Compare(op, Box::new(e))], |
| 333 | 333 | <e:NbSum> => vec![unary_test_from_expr(e)], |
| 334 | | - "[" <lo:Sum> ".." <hi:Sum> <eo:IntervalEnd> => |
| 334 | + "[" <lo:Sum> ".." <hi:Endpoint> <eo:IntervalEnd> => |
| 335 | 335 | vec![UnaryTest::Interval(Interval { start_open: false, start: Box::new(lo), end: Box::new(hi), end_open: eo })], |
| 336 | | - "(" <lo:Sum> ".." <hi:Sum> <eo:IntervalEnd> => |
| 336 | + "(" <lo:Sum> ".." <hi:Endpoint> <eo:IntervalEnd> => |
| 337 | 337 | vec![UnaryTest::Interval(Interval { start_open: true, start: Box::new(lo), end: Box::new(hi), end_open: eo })], |
| 338 | 338 | // Reverse-open interval *test* `x in ]a..b]` (exclusive lower, ≡ `(a..b]`); the |
| 339 | 339 | // lexer's `RBracketOpen` opener keeps this off the `]`-closer LR state. |
| 340 | | - RBracketOpen <lo:Sum> ".." <hi:Sum> <eo:IntervalEnd> => |
| 340 | + RBracketOpen <lo:Sum> ".." <hi:Endpoint> <eo:IntervalEnd> => |
| 341 | 341 | vec![UnaryTest::Interval(Interval { start_open: true, start: Box::new(lo), end: Box::new(hi), end_open: eo })], |
| 342 | 342 | "[" <ts:Comma<UnaryTestElem>> "]" => ts, |
| 343 | 343 | "(" <ts:Comma<UnaryTestElem>> ")" => ts, |
| @@ -407,9 +407,54 @@ |
| 407 | 407 | Name => Expr::Var(<>), |
| 408 | 408 | }; |
| 409 | 409 | |
| 410 | +// The HIGH endpoint of an interval — a filter-free clone of the `Sum` chain. It is |
| 411 | +// identical to `Sum`/`Product`/`Power`/`Unary`/`Postfix` except `EpPostfix` drops the |
| 412 | +// `Postfix "[" Expr "]"` filter production, so a `[` *after* the high endpoint is |
| 413 | +// unambiguously the reverse-CLOSE bracket of `[a..b[` (≡ `[a..b)`), never a subscript. |
| 414 | +// Only the high endpoint needs this — the low endpoint is always followed by `..`, so |
| 415 | +// no `[` can attach there. The base case reuses the shared `Primary` (which carries no |
| 416 | +// filter; the filter lives only in `Postfix`), so a grouping / list / nested range |
| 417 | +// endpoint still parses. Cost: an interval's high endpoint cannot itself end in a |
| 418 | +// `[...]` subscript (e.g. `[a..xs[2]]`) — a shape no test/TCK case uses. Mirrors the |
| 419 | +// `NbSum` precedent (a restricted arithmetic clone for one syntactic position). |
| 420 | +Endpoint: Expr = { |
| 421 | + <l:Endpoint> "+" <r:EpProduct> => Expr::Arith(ArithOp::Add, Box::new(l), Box::new(r)), |
| 422 | + <l:Endpoint> "-" <r:EpProduct> => Expr::Arith(ArithOp::Sub, Box::new(l), Box::new(r)), |
| 423 | + EpProduct, |
| 424 | +}; |
| 425 | + |
| 426 | +EpProduct: Expr = { |
| 427 | + <l:EpProduct> "*" <r:EpPower> => Expr::Arith(ArithOp::Mul, Box::new(l), Box::new(r)), |
| 428 | + <l:EpProduct> "/" <r:EpPower> => Expr::Arith(ArithOp::Div, Box::new(l), Box::new(r)), |
| 429 | + EpPower, |
| 430 | +}; |
| 431 | + |
| 432 | +EpPower: Expr = { |
| 433 | + <l:EpPower> "**" <r:EpUnary> => Expr::Arith(ArithOp::Pow, Box::new(l), Box::new(r)), |
| 434 | + EpUnary, |
| 435 | +}; |
| 436 | + |
| 437 | +EpUnary: Expr = { |
| 438 | + "-" <e:EpUnary> => Expr::Neg(Box::new(e)), |
| 439 | + EpPostfix, |
| 440 | +}; |
| 441 | + |
| 442 | +// Like `Postfix` but WITHOUT the `[Expr]` filter production (see `Endpoint`). |
| 443 | +EpPostfix: Expr = { |
| 444 | + <e:EpPostfix> "." <n:Name> => Expr::Path(Box::new(e), n), |
| 445 | + <n:Name> "(" ")" => Expr::FnCall(n, CallArgs::default()), |
| 446 | + <n:Name> "(" <a:Comma<Arg>> ")" => Expr::FnCall(n, callargs_from(a)), |
| 447 | + Primary, |
| 448 | +}; |
| 449 | + |
| 410 | 450 | IntervalEnd: bool = { |
| 411 | 451 | "]" => false, // closed |
| 412 | 452 | ")" => true, // open |
| 453 | + // Reverse-CLOSE `[a..b[` ≡ `[a..b)`: an exclusive upper bound spelt with a |
| 454 | + // trailing `[`. Admissible only because the high endpoint is the filter-free |
| 455 | + // `Endpoint` nonterminal (no `Postfix "[" Expr "]"`), so this `[` cannot also be |
| 456 | + // a subscript on the endpoint — keeping it LR(1)-clean (build.rs gate). |
| 457 | + "[" => true, // open (reverse-close) |
| 413 | 458 | }; |
| 414 | 459 | |
| 415 | 460 | // `Num` (f64 literal), `Str` (double-quoted, no escapes) and `Name` (a Unicode |