| 140 | } |
| 141 | |
| 142 | pub(super) fn parse_unary(&mut self) { |
| 143 | match self.peek() { |
| 144 | Some(TokenType::Minus) => { |
| 145 | self.advance(); |
| 146 | self.expr_bp(21); |
| 147 | self.chunk.emit(OpCode::Minus, 0); |
| 148 | } |
| 149 | Some(TokenType::Plus) => { |
| 150 | // Unary plus calls `__pos__` and coerces bool to int. |
| 151 | self.advance(); |
| 152 | self.expr_bp(21); |
| 153 | self.chunk.emit(OpCode::Pos, 0); |
| 154 | } |
| 155 | Some(TokenType::Tilde) => { |
| 156 | self.advance(); |
| 157 | self.expr_bp(21); |
| 158 | self.chunk.emit(OpCode::BitNot, 0); |
| 159 | } |
| 160 | Some(TokenType::Await) => { |
| 161 | self.advance(); |
| 162 | self.expr_bp(21); |
| 163 | self.chunk.emit(OpCode::Await, 0); |
| 164 | } |
| 165 | _ => self.parse_atom() |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | /* Atoms: literals, names, numbers, strings, f-strings, containers. */ |
| 170 | pub(super) fn parse_atom(&mut self) { |