MCPcopy Index your code
hub / github.com/RustPython/RustPython / emit_next_token

Function emit_next_token

crates/stdlib/src/_tokenize.rs:150–407  ·  view source on GitHub ↗

Emit the next token from the Yielding phase.

(
        state: &mut TokenizerState,
        extra_tokens: bool,
        vm: &VirtualMachine,
    )

Source from the content-addressed store, hash-verified

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

Callers 1

nextMethod · 0.85

Calls 15

make_token_tupleFunction · 0.85
raise_indentation_errorFunction · 0.85
token_kind_valueFunction · 0.85
next_non_dedent_infoFunction · 0.85
split_fstring_middleFunction · 0.85
find_fstring_middle_typeFunction · 0.85
takeFunction · 0.85
raise_syntax_errorFunction · 0.85
starts_withMethod · 0.80
collectMethod · 0.80
to_stringMethod · 0.80
ErrClass · 0.50

Tested by

no test coverage detected