MCPcopy Create free account
hub / github.com/aiscriptdev/aiscript / scan_number

Method scan_number

aiscript-lexer/src/lib.rs:391–406  ·  view source on GitHub ↗

Scans numeric literals (integers and floats)

(&mut self)

Source from the content-addressed store, hash-verified

389
390 // Scans numeric literals (integers and floats)
391 fn scan_number(&mut self) -> Token<'a> {
392 self.consume_digits();
393 // Look for a fractional part.
394 if self.source[self.current..].len() >= 2 {
395 let mut next_two_chars = self.source[self.current..self.current + 2].chars();
396 let (maybe_dot, maybe_digit) = (next_two_chars.next(), next_two_chars.next());
397 if maybe_dot == Some('.') && matches!(maybe_digit, Some(c) if c.is_ascii_digit()) {
398 // Consume the "."
399 self.advance();
400
401 self.consume_digits();
402 }
403 }
404
405 self.make_token(TokenType::Number)
406 }
407
408 // Helper method to consume consecutive digits
409 fn consume_digits(&mut self) {

Callers 1

scan_tokenMethod · 0.80

Calls 5

consume_digitsMethod · 0.80
lenMethod · 0.80
advanceMethod · 0.80
make_tokenMethod · 0.80
nextMethod · 0.45

Tested by

no test coverage detected