MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / read_number

Method read_number

atomic-core/src/diff/token/tokenizer.rs:373–437  ·  view source on GitHub ↗

Read a number token, handling various numeric formats.

(&mut self)

Source from the content-addressed store, hash-verified

371
372 /// Read a number token, handling various numeric formats.
373 fn read_number(&mut self) -> Token<'a> {
374 let start = self.position;
375
376 // Handle hex (0x), octal (0o), binary (0b)
377 if self.peek() == Some(b'0') {
378 self.advance();
379 if let Some(b) = self.peek() {
380 if matches!(b, b'x' | b'X' | b'o' | b'O' | b'b' | b'B') {
381 self.advance();
382 }
383 }
384 }
385
386 // Read digits (including _ separators)
387 while let Some(b) = self.peek() {
388 if b.is_ascii_hexdigit() || b == b'_' {
389 self.advance();
390 } else {
391 break;
392 }
393 }
394
395 // Handle decimal point and fraction
396 if self.peek() == Some(b'.') && self.peek_at(1).map(|b| b.is_ascii_digit()).unwrap_or(false)
397 {
398 self.advance(); // consume '.'
399 while let Some(b) = self.peek() {
400 if b.is_ascii_digit() || b == b'_' {
401 self.advance();
402 } else {
403 break;
404 }
405 }
406 }
407
408 // Handle exponent (e.g., 1e10, 2.5E-3)
409 if let Some(b'e' | b'E') = self.peek() {
410 self.advance();
411 if let Some(b'+' | b'-') = self.peek() {
412 self.advance();
413 }
414 while let Some(b) = self.peek() {
415 if b.is_ascii_digit() {
416 self.advance();
417 } else {
418 break;
419 }
420 }
421 }
422
423 // Handle type suffix (f32, i64, u8, etc.)
424 while let Some(b) = self.peek() {
425 if b.is_ascii_alphabetic() {
426 self.advance();
427 } else {
428 break;
429 }
430 }

Callers 1

nextMethod · 0.80

Calls 3

peek_atMethod · 0.80
peekMethod · 0.45
advanceMethod · 0.45

Tested by

no test coverage detected