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

Method dict_tail

compiler/src/modules/parser/literals.rs:100–116  ·  view source on GitHub ↗

Finishes a `{}` dict after the first pair. `pairs` = loose key/val pairs on the stack; `incremental` = a Dict object is already on the stack. On the first `**` the loose pairs are consolidated with `BuildDict pairs`, then merges use `DictUpdate`/`MapAdd`. */

(&mut self, mut pairs: u16, mut incremental: bool)

Source from the content-addressed store, hash-verified

98
99 /* Finishes a `{}` dict after the first pair. `pairs` = loose key/val pairs on the stack; `incremental` = a Dict object is already on the stack. On the first `**` the loose pairs are consolidated with `BuildDict pairs`, then merges use `DictUpdate`/`MapAdd`. */
100 fn dict_tail(&mut self, mut pairs: u16, mut incremental: bool) {
101 while self.eat_if(TokenType::Comma) {
102 if matches!(self.peek(), Some(TokenType::Rbrace)) { break; }
103 if self.eat_if(TokenType::DoubleStar) {
104 if !incremental { self.chunk.emit(OpCode::BuildDict, pairs); incremental = true; }
105 self.expr();
106 self.chunk.emit(OpCode::DictUpdate, 0);
107 } else {
108 self.expr();
109 self.eat(TokenType::Colon);
110 self.expr();
111 if incremental { self.chunk.emit(OpCode::MapAdd, 0); } else { pairs += 1; }
112 }
113 }
114 self.eat(TokenType::Rbrace);
115 if !incremental { self.chunk.emit(OpCode::BuildDict, pairs); }
116 }
117
118 /* Finishes a `{}` set after the first element; mirrors `dict_tail` with `SetUpdate`/`SetAdd` and `BuildSet`. */
119 fn set_tail(&mut self, mut count: u16, mut incremental: bool) {

Callers 1

brace_literalMethod · 0.80

Calls 4

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

Tested by

no test coverage detected