Subscript after `[`: plain index or `a:b:c` slice with None defaults. Eats the closing `]`; emits BuildSlice for slices. Returns true when a slice was built. */
(&mut self)
| 317 | |
| 318 | /* Subscript after `[`: plain index or `a:b:c` slice with None defaults. Eats the closing `]`; emits BuildSlice for slices. Returns true when a slice was built. */ |
| 319 | pub(super) fn parse_subscript(&mut self) -> bool { |
| 320 | if matches!(self.peek(), Some(TokenType::Colon)) { |
| 321 | self.chunk.emit(OpCode::LoadNone, 0); |
| 322 | } else { |
| 323 | self.expr(); |
| 324 | } |
| 325 | if self.eat_if(TokenType::Colon) { |
| 326 | let mut parts = 2u16; |
| 327 | if matches!(self.peek(), Some(TokenType::Colon | TokenType::Rsqb)) { |
| 328 | self.chunk.emit(OpCode::LoadNone, 0); |
| 329 | } else { |
| 330 | self.expr(); |
| 331 | } |
| 332 | if self.eat_if(TokenType::Colon) { |
| 333 | parts = 3; |
| 334 | if matches!(self.peek(), Some(TokenType::Rsqb)) { |
| 335 | self.chunk.emit(OpCode::LoadNone, 0); |
| 336 | } else { |
| 337 | self.expr(); |
| 338 | } |
| 339 | } |
| 340 | self.eat(TokenType::Rsqb); |
| 341 | self.chunk.emit(OpCode::BuildSlice, parts); |
| 342 | true |
| 343 | } else { |
| 344 | self.eat(TokenType::Rsqb); |
| 345 | false |
| 346 | } |
| 347 | } |
| 348 | |
| 349 | /* Postfix trailers: `.attr`, [i], [s:e], (args), chained. A trailer must start on the same line, so a statement boundary ends the chain (else `x = []` ⏎ `[i]` parses as `[][i]`). */ |
| 350 | pub(super) fn postfix_tail(&mut self) { |
no test coverage detected