@@ -318,47 +318,65 @@ impure fn consume_block_comment(reader rdr) {
318
318
be consume_any_whitespace ( rdr) ;
319
319
}
320
320
321
- impure fn scan_dec_digits ( reader rdr) -> int {
322
-
323
- auto c = rdr. curr ( ) ;
321
+ fn digits_to_string ( str s) -> int {
324
322
325
323
let int accum_int = 0 ;
324
+ let int i = 0 ;
326
325
327
- while ( is_dec_digit ( c) || c == '_' ) {
328
- if ( c != '_' ) {
329
- accum_int *= 10 ;
330
- accum_int += dec_digit_val ( c) ;
331
- }
332
- rdr. bump ( ) ;
333
- c = rdr. curr ( ) ;
326
+ for ( u8 c in s) {
327
+ accum_int *= 10 ;
328
+ accum_int += dec_digit_val ( c as char ) ;
334
329
}
335
330
336
331
ret accum_int;
337
332
}
338
333
339
- impure fn scan_exponent ( reader rdr) -> option. t[ int ] {
334
+ impure fn scan_exponent ( reader rdr) -> option. t[ str ] {
340
335
auto c = rdr. curr ( ) ;
341
- auto sign = 1 ;
336
+ auto res = "" ;
342
337
343
338
if ( c == 'e' || c == 'E' ) {
339
+ res += _str. from_bytes ( vec ( c as u8 ) ) ;
344
340
rdr. bump ( ) ;
345
341
c = rdr. curr ( ) ;
346
- if ( c == '-' ) {
347
- sign = -1 ;
348
- rdr. bump ( ) ;
349
- } else if ( c == '+' ) {
342
+ if ( c == '-' || c == '+' ) {
343
+ res += _str. from_bytes ( vec ( c as u8 ) ) ;
350
344
rdr. bump ( ) ;
351
345
}
352
346
auto exponent = scan_dec_digits ( rdr) ;
353
- ret ( some ( sign * exponent) ) ;
347
+ if ( _str. byte_len ( exponent) > 0 u) {
348
+ ret ( some ( res + exponent) ) ;
349
+ }
350
+ else {
351
+ log ( "scan_exponent: bad fp literal" ) ;
352
+ fail;
353
+ }
354
354
}
355
355
else {
356
- ret none[ int ] ;
356
+ ret none[ str ] ;
357
357
}
358
358
}
359
359
360
+ impure fn scan_dec_digits ( reader rdr) -> str {
361
+
362
+ auto c = rdr. curr ( ) ;
363
+ let str res = "" ;
364
+
365
+ while ( is_dec_digit ( c) || c == '_' ) {
366
+ if ( c != '_' ) {
367
+ res += _str. from_bytes ( vec ( c as u8 ) ) ;
368
+ }
369
+ rdr. bump ( ) ;
370
+ c = rdr. curr ( ) ;
371
+ }
372
+
373
+ ret res;
374
+ }
375
+
360
376
impure fn scan_number ( mutable char c, reader rdr) -> token . token {
361
377
auto accum_int = 0 ;
378
+ let str dec_str = "" ;
379
+ let bool is_dec_integer = false ;
362
380
auto n = rdr. next ( ) ;
363
381
364
382
if ( c == '0' && n == 'x' ) {
@@ -386,7 +404,12 @@ impure fn scan_number(mutable char c, reader rdr) -> token.token {
386
404
c = rdr. curr ( ) ;
387
405
}
388
406
} else {
389
- accum_int = scan_dec_digits ( rdr) ;
407
+ dec_str = scan_dec_digits ( rdr) ;
408
+ is_dec_integer = true ;
409
+ }
410
+
411
+ if ( is_dec_integer) {
412
+ accum_int = digits_to_string ( dec_str) ;
390
413
}
391
414
392
415
c = rdr. curr ( ) ;
@@ -443,20 +466,19 @@ impure fn scan_number(mutable char c, reader rdr) -> token.token {
443
466
}
444
467
}
445
468
c = rdr. curr ( ) ;
469
+
446
470
if ( c == '.' ) {
447
471
// Parse a floating-point number.
448
472
rdr. bump ( ) ;
449
- auto accum_int1 = scan_dec_digits ( rdr) ;
450
- auto base_str = _int. to_str ( accum_int, 10 u) + "."
451
- + _int. to_str ( accum_int1, 10 u) ;
473
+ auto dec_part = scan_dec_digits ( rdr) ;
474
+ auto float_str = dec_str + "." + dec_part;
452
475
c = rdr. curr ( ) ;
453
- auto exponent_str = "" ;
454
- let option. t[ int] maybe_exponent = scan_exponent ( rdr) ;
455
- alt ( maybe_exponent) {
456
- case ( some[ int] ( ?i) ) {
457
- exponent_str = "e" + _int. to_str ( i, 10 u) ;
476
+ auto exponent_str = scan_exponent ( rdr) ;
477
+ alt ( exponent_str) {
478
+ case ( some[ str] ( ?s) ) {
479
+ float_str += s;
458
480
}
459
- case ( none[ int ] ) {
481
+ case ( none[ str ] ) {
460
482
}
461
483
}
462
484
@@ -468,27 +490,28 @@ impure fn scan_number(mutable char c, reader rdr) -> token.token {
468
490
if ( c == '3' && n == '2' ) {
469
491
rdr. bump ( ) ; rdr. bump ( ) ;
470
492
ret token. LIT_MACH_FLOAT ( util. common . ty_f32 ,
471
- base_str + exponent_str ) ;
493
+ float_str ) ;
472
494
}
473
495
else if ( c == '6' && n == '4' ) {
474
496
rdr. bump ( ) ; rdr. bump ( ) ;
475
497
ret token. LIT_MACH_FLOAT ( util. common . ty_f64 ,
476
- base_str + exponent_str) ;
498
+ float_str) ;
499
+ /* FIXME: if this is out of range for either a 32-bit or
500
+ 64-bit float, it won't be noticed till the back-end */
477
501
}
478
502
}
479
503
else {
480
- ret token. LIT_FLOAT ( base_str + exponent_str ) ;
504
+ ret token. LIT_FLOAT ( float_str ) ;
481
505
}
482
506
}
483
507
484
508
auto maybe_exponent = scan_exponent ( rdr) ;
485
509
alt ( maybe_exponent) {
486
- case ( some[ int] ( ?i) ) {
487
- ret token. LIT_FLOAT ( _int. to_str ( accum_int, 10 u)
488
- + "e" + _int. to_str ( i, 10 u) ) ;
510
+ case ( some[ str] ( ?s) ) {
511
+ ret token. LIT_FLOAT ( dec_str + s) ;
489
512
}
490
- case ( none[ int ] ) {
491
- ret token. LIT_INT ( accum_int) ;
513
+ case ( none[ str ] ) {
514
+ ret token. LIT_INT ( accum_int) ;
492
515
}
493
516
}
494
517
}
0 commit comments