about summary refs log tree commit diff
path: root/src/libsyntax/parse
diff options
context:
space:
mode:
authorSiegeLord <slabode@aim.com>2014-01-11 13:53:06 -0500
committerSiegeLord <slabode@aim.com>2014-01-11 14:21:59 -0500
commit5ea6d0201d54c35205b7c4538b997692aa4f1a91 (patch)
tree8638f991e17bb3a570fa1a2d7bc3f74a2fd98495 /src/libsyntax/parse
parent4bdda359c3cf41e36ba01ca6aef826aca7cc81c0 (diff)
downloadrust-5ea6d0201d54c35205b7c4538b997692aa4f1a91.tar.gz
rust-5ea6d0201d54c35205b7c4538b997692aa4f1a91.zip
Tighten up float literal lexing.
Specifically, dissallow setting the number base for every type of float
literal, not only those that contain the decimal point. This is in line with
the description in the manual.
Diffstat (limited to 'src/libsyntax/parse')
-rw-r--r--src/libsyntax/parse/lexer.rs27
1 files changed, 16 insertions, 11 deletions
diff --git a/src/libsyntax/parse/lexer.rs b/src/libsyntax/parse/lexer.rs
index 4cd64331f9a..885cfbcbdbe 100644
--- a/src/libsyntax/parse/lexer.rs
+++ b/src/libsyntax/parse/lexer.rs
@@ -463,6 +463,19 @@ fn scan_digits(rdr: @StringReader, radix: uint) -> ~str {
     };
 }
 
+fn check_float_base(rdr: @StringReader, start_bpos: BytePos, last_bpos: BytePos,
+                    base: uint) {
+    match base {
+      16u => fatal_span(rdr, start_bpos, last_bpos,
+                      ~"hexadecimal float literal is not supported"),
+      8u => fatal_span(rdr, start_bpos, last_bpos,
+                     ~"octal float literal is not supported"),
+      2u => fatal_span(rdr, start_bpos, last_bpos,
+                     ~"binary float literal is not supported"),
+      _ => ()
+    }
+}
+
 fn scan_number(c: char, rdr: @StringReader) -> token::Token {
     let mut num_str;
     let mut base = 10u;
@@ -540,17 +553,6 @@ fn scan_number(c: char, rdr: @StringReader) -> token::Token {
         num_str.push_char('.');
         num_str.push_str(dec_part);
     }
-    if is_float {
-        match base {
-          16u => fatal_span(rdr, start_bpos, rdr.last_pos.get(),
-                            ~"hexadecimal float literal is not supported"),
-          8u => fatal_span(rdr, start_bpos, rdr.last_pos.get(),
-                           ~"octal float literal is not supported"),
-          2u => fatal_span(rdr, start_bpos, rdr.last_pos.get(),
-                           ~"binary float literal is not supported"),
-          _ => ()
-        }
-    }
     match scan_exponent(rdr, start_bpos) {
       Some(ref s) => {
         is_float = true;
@@ -566,10 +568,12 @@ fn scan_number(c: char, rdr: @StringReader) -> token::Token {
         if c == '3' && n == '2' {
             bump(rdr);
             bump(rdr);
+            check_float_base(rdr, start_bpos, rdr.last_pos.get(), base);
             return token::LIT_FLOAT(str_to_ident(num_str), ast::TyF32);
         } else if c == '6' && n == '4' {
             bump(rdr);
             bump(rdr);
+            check_float_base(rdr, start_bpos, rdr.last_pos.get(), base);
             return token::LIT_FLOAT(str_to_ident(num_str), ast::TyF64);
             /* FIXME (#2252): if this is out of range for either a
             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 {
         }
     }
     if is_float {
+        check_float_base(rdr, start_bpos, rdr.last_pos.get(), base);
         return token::LIT_FLOAT_UNSUFFIXED(str_to_ident(num_str));
     } else {
         if num_str.len() == 0u {