Emit the next token from the Yielding phase.
(
state: &mut TokenizerState,
extra_tokens: bool,
vm: &VirtualMachine,
)
| 148 | |
| 149 | /// Emit the next token from the Yielding phase. |
| 150 | fn emit_next_token( |
| 151 | state: &mut TokenizerState, |
| 152 | extra_tokens: bool, |
| 153 | vm: &VirtualMachine, |
| 154 | ) -> PyResult<PyIterReturn> { |
| 155 | let TokenizerPhase::Yielding { |
| 156 | source, |
| 157 | tokens, |
| 158 | errors, |
| 159 | index, |
| 160 | line_index, |
| 161 | need_implicit_nl, |
| 162 | pending_fstring_parts, |
| 163 | pending_empty_fstring_middle, |
| 164 | } = &mut state.phase |
| 165 | else { |
| 166 | unreachable!() |
| 167 | }; |
| 168 | |
| 169 | // Emit pending empty FSTRING_MIDDLE (for format spec nesting) |
| 170 | if let Some((mid_type, mid_line, mid_col, mid_line_str)) = |
| 171 | pending_empty_fstring_middle.take() |
| 172 | { |
| 173 | return Ok(PyIterReturn::Return(make_token_tuple( |
| 174 | vm, |
| 175 | mid_type, |
| 176 | "", |
| 177 | mid_line, |
| 178 | mid_col as isize, |
| 179 | mid_line, |
| 180 | mid_col as isize, |
| 181 | &mid_line_str, |
| 182 | ))); |
| 183 | } |
| 184 | |
| 185 | // Emit any pending fstring sub-tokens first |
| 186 | if let Some((tok_type, tok_str, sl, sc, el, ec)) = pending_fstring_parts.pop() { |
| 187 | let offset: usize = source |
| 188 | .lines() |
| 189 | .take(sl.saturating_sub(1)) |
| 190 | .map(|l| l.len() + 1) |
| 191 | .sum(); |
| 192 | let full_line = source.full_line_str(TextSize::from(offset.min(source.len()) as u32)); |
| 193 | return Ok(PyIterReturn::Return(make_token_tuple( |
| 194 | vm, |
| 195 | tok_type, |
| 196 | &tok_str, |
| 197 | sl, |
| 198 | sc as isize, |
| 199 | el, |
| 200 | ec as isize, |
| 201 | full_line, |
| 202 | ))); |
| 203 | } |
| 204 | |
| 205 | let source_len = TextSize::from(source.len() as u32); |
| 206 | |
| 207 | while *index < tokens.len() { |
no test coverage detected