@@ -463,6 +463,19 @@ fn scan_digits(rdr: @StringReader, radix: uint) -> ~str {
463
463
} ;
464
464
}
465
465
466
+ fn check_float_base ( rdr : @StringReader , start_bpos : BytePos , last_bpos : BytePos ,
467
+ base : uint ) {
468
+ match base {
469
+ 16 u => fatal_span ( rdr, start_bpos, last_bpos,
470
+ ~"hexadecimal float literal is not supported") ,
471
+ 8 u => fatal_span ( rdr, start_bpos, last_bpos,
472
+ ~"octal float literal is not supported") ,
473
+ 2 u => fatal_span ( rdr, start_bpos, last_bpos,
474
+ ~"binary float literal is not supported") ,
475
+ _ => ( )
476
+ }
477
+ }
478
+
466
479
fn scan_number( c : char , rdr : @StringReader ) -> token:: Token {
467
480
let mut num_str;
468
481
let mut base = 10 u;
@@ -540,17 +553,6 @@ fn scan_number(c: char, rdr: @StringReader) -> token::Token {
540
553
num_str. push_char ( '.' ) ;
541
554
num_str. push_str ( dec_part) ;
542
555
}
543
- if is_float {
544
- match base {
545
- 16 u => fatal_span ( rdr, start_bpos, rdr. last_pos . get ( ) ,
546
- ~"hexadecimal float literal is not supported") ,
547
- 8 u => fatal_span ( rdr, start_bpos, rdr. last_pos . get ( ) ,
548
- ~"octal float literal is not supported") ,
549
- 2 u => fatal_span ( rdr, start_bpos, rdr. last_pos . get ( ) ,
550
- ~"binary float literal is not supported") ,
551
- _ => ( )
552
- }
553
- }
554
556
match scan_exponent ( rdr, start_bpos) {
555
557
Some ( ref s) => {
556
558
is_float = true ;
@@ -566,10 +568,12 @@ fn scan_number(c: char, rdr: @StringReader) -> token::Token {
566
568
if c == '3' && n == '2' {
567
569
bump ( rdr) ;
568
570
bump ( rdr) ;
571
+ check_float_base ( rdr, start_bpos, rdr. last_pos . get ( ) , base) ;
569
572
return token:: LIT_FLOAT ( str_to_ident ( num_str) , ast:: TyF32 ) ;
570
573
} else if c == '6' && n == '4' {
571
574
bump ( rdr) ;
572
575
bump ( rdr) ;
576
+ check_float_base ( rdr, start_bpos, rdr. last_pos . get ( ) , base) ;
573
577
return token:: LIT_FLOAT ( str_to_ident ( num_str) , ast:: TyF64 ) ;
574
578
/* FIXME (#2252): if this is out of range for either a
575
579
32-bit or 64-bit float, it won't be noticed till the
@@ -580,6 +584,7 @@ fn scan_number(c: char, rdr: @StringReader) -> token::Token {
580
584
}
581
585
}
582
586
if is_float {
587
+ check_float_base ( rdr, start_bpos, rdr. last_pos . get ( ) , base) ;
583
588
return token:: LIT_FLOAT_UNSUFFIXED ( str_to_ident ( num_str) ) ;
584
589
} else {
585
590
if num_str. len ( ) == 0 u {
0 commit comments