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

Method next_token

compiler/src/modules/lexer/scan.rs:345–505  ·  view source on GitHub ↗

Main dispatch: drains pending queue, then routes each byte via BYTE_CLASS / SINGLE_TOK lookups. */

(&mut self)

Source from the content-addressed store, hash-verified

343
344 /* Main dispatch: drains pending queue, then routes each byte via BYTE_CLASS / SINGLE_TOK lookups. */
345 pub fn next_token(&mut self) -> Option<(TokenType, usize, usize, usize)> {
346 if let Some(tok) = self.pending.pop() {
347 return Some(tok);
348 }
349
350 self.skip_whitespace();
351 if self.pos >= self.src.len() { return None; }
352
353 let start = self.pos;
354 let line_at_start = self.line;
355 let b = self.src[self.pos];
356 let cl = BYTE_CLASS[b as usize];
357
358 // Newline
359 if b == b'\n' {
360 self.pos += 1;
361 self.handle_newline(start);
362 return self.pending.pop();
363 }
364
365 if b == b'#' { // inside an f-string interpolation, '#' is part of the format spec, skip silently
366 if !self.fstring_stack.is_empty() {
367 self.pos += 1;
368 return self.next_token();
369 }
370 while self.pos < self.src.len() && self.src[self.pos] != b'\n' {
371 self.pos += 1;
372 }
373 return Some((TokenType::Comment, line_at_start, start, self.pos));
374 }
375
376 // Identifier / keyword / string-prefix / f-string-prefix
377 if cl & ID_START != 0 {
378 self.pos += if b >= 0x80 { utf8_char_len(b) } else { 1 };
379 self.scan_id_rest();
380 let slice = &self.src[start..self.pos];
381
382 if is_fstring_prefix(slice)
383 && let Some(&q) = self.src.get(self.pos)
384 && (q == b'"' || q == b'\'')
385 {
386 let pe = self.pos;
387 self.start_fstring(start, pe);
388 return self.pending.pop();
389 }
390
391 if is_string_prefix(slice)
392 && let Some(&q) = self.src.get(self.pos)
393 && (q == b'"' || q == b'\'')
394 {
395 let q_start = self.pos;
396 self.pos += 1;
397 self.scan_string(q, q_start);
398 return Some((TokenType::String, line_at_start, start, self.pos));
399 }
400
401 /* Bytes literal (b/B, optional r/R for raw): scans like a string, the parser decodes bytes-specific escapes later. */
402 if is_bytes_prefix(slice)

Callers 1

lexFunction · 0.45

Calls 15

utf8_char_lenFunction · 0.85
is_fstring_prefixFunction · 0.85
is_string_prefixFunction · 0.85
is_bytes_prefixFunction · 0.85
keywordFunction · 0.85
skip_whitespaceMethod · 0.80
handle_newlineMethod · 0.80
scan_id_restMethod · 0.80
start_fstringMethod · 0.80
scan_stringMethod · 0.80
scan_numberMethod · 0.80
scan_dot_numberMethod · 0.80

Tested by

no test coverage detected