MCPcopy Create free account
hub / github.com/dylan-sutton-chavez/edge-python / parse_subscript

Method parse_subscript

compiler/src/modules/parser/expr.rs:319–347  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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) {

Callers 3

name_stmtMethod · 0.80
parse_del_targetMethod · 0.80
postfix_tailMethod · 0.80

Calls 4

emitMethod · 0.80
exprMethod · 0.80
eat_ifMethod · 0.80
eatMethod · 0.80

Tested by

no test coverage detected