about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--doc/po/ja/rust.md.po8
-rw-r--r--doc/po/ja/tutorial.md.po2
-rw-r--r--doc/po/rust.md.pot10
-rw-r--r--doc/po/tutorial.md.pot2
-rw-r--r--doc/rust.md5
-rw-r--r--doc/tutorial.md2
-rw-r--r--src/etc/gedit/share/gtksourceview-3.0/language-specs/rust.lang5
-rw-r--r--src/etc/kate/rust.xml1
-rw-r--r--src/etc/vim/syntax/rust.vim4
-rw-r--r--src/libsyntax/parse/lexer.rs13
-rw-r--r--src/test/compile-fail/no-oct-float-literal.rs17
-rw-r--r--src/test/run-pass/integer-literal-radix.rs27
12 files changed, 91 insertions, 5 deletions
diff --git a/doc/po/ja/rust.md.po b/doc/po/ja/rust.md.po
index 0313a3379b7..42237b9d6cc 100644
--- a/doc/po/ja/rust.md.po
+++ b/doc/po/ja/rust.md.po
@@ -681,6 +681,13 @@ msgstr ""
 #. type: Bullet: '  * '
 #: doc/rust.md:326
 msgid ""
+"An _octal literal_ starts with the character sequence `U+0030` `U+006F` (`0o`) "
+"and continues as any mixture octal digits and underscores."
+msgstr ""
+
+#. type: Bullet: '  * '
+#: doc/rust.md:326
+msgid ""
 "A _binary literal_ starts with the character sequence `U+0030` `U+0062` "
 "(`0b`) and continues as any mixture binary digits and underscores."
 msgstr ""
@@ -740,6 +747,7 @@ msgid ""
 "123u;                              // type uint\n"
 "123_u;                             // type uint\n"
 "0xff_u8;                           // type u8\n"
+"0o70_i16;                          // type i16\n"
 "0b1111_1111_1001_0000_i32;         // type i32\n"
 "~~~~\n"
 msgstr ""
diff --git a/doc/po/ja/tutorial.md.po b/doc/po/ja/tutorial.md.po
index 076ef7f2452..26dc7bf0db8 100644
--- a/doc/po/ja/tutorial.md.po
+++ b/doc/po/ja/tutorial.md.po
@@ -849,7 +849,7 @@ msgstr "## プリミティブ型とリテラル"
 msgid ""
 "There are general signed and unsigned integer types, `int` and `uint`, as "
 "well as 8-, 16-, 32-, and 64-bit variants, `i8`, `u16`, etc.  Integers can "
-"be written in decimal (`144`), hexadecimal (`0x90`), or binary "
+"be written in decimal (`144`), hexadecimal (`0x90`), octal (`0o70`), or binary "
 "(`0b10010000`) base. Each integral type has a corresponding literal suffix "
 "that can be used to indicate the type of a literal: `i` for `int`, `u` for "
 "`uint`, `i8` for the `i8` type."
diff --git a/doc/po/rust.md.pot b/doc/po/rust.md.pot
index 31056378a48..9acefdf8215 100644
--- a/doc/po/rust.md.pot
+++ b/doc/po/rust.md.pot
@@ -661,7 +661,7 @@ msgstr ""
 
 #. type: Plain text
 #: doc/rust.md:319
-msgid "An _integer literal_ has one of three forms:"
+msgid "An _integer literal_ has one of four forms:"
 msgstr ""
 
 #. type: Bullet: '  * '
@@ -681,6 +681,13 @@ msgstr ""
 #. type: Bullet: '  * '
 #: doc/rust.md:326
 msgid ""
+"An _octal literal_ starts with the character sequence `U+0030` `U+006F` (`0o`) "
+"and continues as any mixture octal digits and underscores."
+msgstr ""
+
+#. type: Bullet: '  * '
+#: doc/rust.md:326
+msgid ""
 "A _binary literal_ starts with the character sequence `U+0030` `U+0062` "
 "(`0b`) and continues as any mixture binary digits and underscores."
 msgstr ""
@@ -740,6 +747,7 @@ msgid ""
 "123u;                              // type uint\n"
 "123_u;                             // type uint\n"
 "0xff_u8;                           // type u8\n"
+"0o70_i16;                          // type i16\n"
 "0b1111_1111_1001_0000_i32;         // type i32\n"
 "~~~~\n"
 msgstr ""
diff --git a/doc/po/tutorial.md.pot b/doc/po/tutorial.md.pot
index fc0403da218..a9c93aa6a8b 100644
--- a/doc/po/tutorial.md.pot
+++ b/doc/po/tutorial.md.pot
@@ -646,7 +646,7 @@ msgstr ""
 msgid ""
 "There are general signed and unsigned integer types, `int` and `uint`, as "
 "well as 8-, 16-, 32-, and 64-bit variants, `i8`, `u16`, etc.  Integers can "
-"be written in decimal (`144`), hexadecimal (`0x90`), or binary "
+"be written in decimal (`144`), hexadecimal (`0x90`), octal (`0o70`), or binary "
 "(`0b10010000`) base. Each integral type has a corresponding literal suffix "
 "that can be used to indicate the type of a literal: `i` for `int`, `u` for "
 "`uint`, `i8` for the `i8` type."
diff --git a/doc/rust.md b/doc/rust.md
index 1e1a21c8ee9..389ea58ee15 100644
--- a/doc/rust.md
+++ b/doc/rust.md
@@ -340,12 +340,14 @@ as they are differentiated by suffixes.
 
 ##### Integer literals
 
-An _integer literal_ has one of three forms:
+An _integer literal_ has one of four forms:
 
   * A _decimal literal_ starts with a *decimal digit* and continues with any
     mixture of *decimal digits* and _underscores_.
   * A _hex literal_ starts with the character sequence `U+0030` `U+0078`
     (`0x`) and continues as any mixture hex digits and underscores.
+  * An _octal literal_ starts with the character sequence `U+0030` `U+006F`
+    (`0o`) and continues as any mixture octal digits and underscores.
   * A _binary literal_ starts with the character sequence `U+0030` `U+0062`
     (`0b`) and continues as any mixture binary digits and underscores.
 
@@ -376,6 +378,7 @@ Examples of integer literals of various forms:
 123u;                              // type uint
 123_u;                             // type uint
 0xff_u8;                           // type u8
+0o70_i16;                          // type i16
 0b1111_1111_1001_0000_i32;         // type i32
 ~~~~
 
diff --git a/doc/tutorial.md b/doc/tutorial.md
index fff5909dc89..5d233004929 100644
--- a/doc/tutorial.md
+++ b/doc/tutorial.md
@@ -305,7 +305,7 @@ fn is_four(x: int) -> bool {
 
 There are general signed and unsigned integer types, `int` and `uint`,
 as well as 8-, 16-, 32-, and 64-bit variants, `i8`, `u16`, etc.
-Integers can be written in decimal (`144`), hexadecimal (`0x90`), or
+Integers can be written in decimal (`144`), hexadecimal (`0x90`), octal (`0o70`), or
 binary (`0b10010000`) base. Each integral type has a corresponding literal
 suffix that can be used to indicate the type of a literal: `i` for `int`,
 `u` for `uint`, `i8` for the `i8` type.
diff --git a/src/etc/gedit/share/gtksourceview-3.0/language-specs/rust.lang b/src/etc/gedit/share/gtksourceview-3.0/language-specs/rust.lang
index 1c1bb0a0012..b8841ebe568 100644
--- a/src/etc/gedit/share/gtksourceview-3.0/language-specs/rust.lang
+++ b/src/etc/gedit/share/gtksourceview-3.0/language-specs/rust.lang
@@ -224,6 +224,10 @@
       [0-9a-fA-F]
     </define-regex>
 
+    <define-regex id="oct_digit" extended="true">
+      [0-7]
+    </define-regex>
+
     <context id="number" style-ref="number">
       <match extended="true">
         ((?&lt;=\.\.)|(?&lt;![\w\.]))
@@ -231,6 +235,7 @@
         [1-9][0-9_]*\%{num_suffix}?|
         0[0-9_]*\%{num_suffix}?|
         0b[01_]+\%{int_suffix}?|
+        0o(\%{oct_digit}|_)+\%{int_suffix}?|
         0x(\%{hex_digit}|_)+\%{int_suffix}?
         )
         ((?![\w\.].)|(?=\.\.))
diff --git a/src/etc/kate/rust.xml b/src/etc/kate/rust.xml
index 17e3e06db35..5efd393fc35 100644
--- a/src/etc/kate/rust.xml
+++ b/src/etc/kate/rust.xml
@@ -199,6 +199,7 @@
 			<Detect2Chars char="/" char1="/" attribute="Comment" context="Commentar 1"/>
 			<Detect2Chars char="/" char1="*" attribute="Comment" context="Commentar 2" beginRegion="Comment"/>
 			<RegExpr String="0x[0-9a-fA-F_]+&rustIntSuf;" attribute="Number" context="#stay"/>
+			<RegExpr String="0o[0-7_]+&rustIntSuf;" attribute="Number" context="#stay"/>
 			<RegExpr String="0b[0-1_]+&rustIntSuf;" attribute="Number" context="#stay"/>
 			<RegExpr String="[0-9][0-9_]*\.[0-9_]*([eE][+-]?[0-9_]+)?(f32|f64|f)?" attribute="Number" context="#stay"/>
 			<RegExpr String="[0-9][0-9_]*&rustIntSuf;" attribute="Number" context="#stay"/>
diff --git a/src/etc/vim/syntax/rust.vim b/src/etc/vim/syntax/rust.vim
index a0a239284ce..e5ff089e2e1 100644
--- a/src/etc/vim/syntax/rust.vim
+++ b/src/etc/vim/syntax/rust.vim
@@ -161,6 +161,9 @@ syn match     rustNumber      display "\<[0-9][0-9_]*\(i\|i8\|i16\|i32\|i64\)\>"
 syn match     rustHexNumber   display "\<0x[a-fA-F0-9_]\+\>"
 syn match     rustHexNumber   display "\<0x[a-fA-F0-9_]\+\(u\|u8\|u16\|u32\|u64\)\>"
 syn match     rustHexNumber   display "\<0x[a-fA-F0-9_]\+\(i8\|i16\|i32\|i64\)\>"
+syn match     rustOctNumber   display "\<0o[0-7_]\+\>"
+syn match     rustOctNumber   display "\<0o[0-7_]\+\(u\|u8\|u16\|u32\|u64\)\>"
+syn match     rustOctNumber   display "\<0o[0-7_]\+\(i8\|i16\|i32\|i64\)\>"
 syn match     rustBinNumber   display "\<0b[01_]\+\>"
 syn match     rustBinNumber   display "\<0b[01_]\+\(u\|u8\|u16\|u32\|u64\)\>"
 syn match     rustBinNumber   display "\<0b[01_]\+\(i8\|i16\|i32\|i64\)\>"
@@ -198,6 +201,7 @@ syn region rustFoldBraces start="{" end="}" transparent fold
 
 " Default highlighting {{{1
 hi def link rustHexNumber       rustNumber
+hi def link rustOctNumber       rustNumber
 hi def link rustBinNumber       rustNumber
 hi def link rustIdentifierPrime rustIdentifier
 hi def link rustTrait           rustType
diff --git a/src/libsyntax/parse/lexer.rs b/src/libsyntax/parse/lexer.rs
index 49445312a12..06a2c557e42 100644
--- a/src/libsyntax/parse/lexer.rs
+++ b/src/libsyntax/parse/lexer.rs
@@ -276,6 +276,11 @@ fn hex_digit_val(c: char) -> int {
     fail!();
 }
 
+fn oct_digit_val(c: char) -> int {
+    if in_range(c, '0', '7') { return (c as int) - ('0' as int); }
+    fail!();
+}
+
 fn bin_digit_value(c: char) -> int { if c == '0' { return 0; } return 1; }
 
 pub fn is_whitespace(c: char) -> bool {
@@ -293,6 +298,8 @@ fn is_hex_digit(c: char) -> bool {
             in_range(c, 'A', 'F');
 }
 
+fn is_oct_digit(c: char) -> bool { return in_range(c, '0', '7'); }
+
 fn is_bin_digit(c: char) -> bool { return c == '0' || c == '1'; }
 
 // EFFECT: eats whitespace and comments.
@@ -464,6 +471,10 @@ fn scan_number(c: char, rdr: @mut StringReader) -> token::Token {
         bump(rdr);
         bump(rdr);
         base = 16u;
+    } else if c == '0' && n == 'o' {
+        bump(rdr);
+        bump(rdr);
+        base = 8u;
     } else if c == '0' && n == 'b' {
         bump(rdr);
         bump(rdr);
@@ -529,6 +540,8 @@ fn scan_number(c: char, rdr: @mut StringReader) -> token::Token {
         match base {
           16u => fatal_span(rdr, start_bpos, rdr.last_pos,
                             ~"hexadecimal float literal is not supported"),
+          8u => fatal_span(rdr, start_bpos, rdr.last_pos,
+                           ~"octal float literal is not supported"),
           2u => fatal_span(rdr, start_bpos, rdr.last_pos,
                            ~"binary float literal is not supported"),
           _ => ()
diff --git a/src/test/compile-fail/no-oct-float-literal.rs b/src/test/compile-fail/no-oct-float-literal.rs
new file mode 100644
index 00000000000..511116b1c55
--- /dev/null
+++ b/src/test/compile-fail/no-oct-float-literal.rs
@@ -0,0 +1,17 @@
+// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// error-pattern:octal float literal is not supported
+
+fn main() {
+    0o123f64;
+    0o123.456;
+    0o123p4f;
+}
diff --git a/src/test/run-pass/integer-literal-radix.rs b/src/test/run-pass/integer-literal-radix.rs
new file mode 100644
index 00000000000..0423e7b89f0
--- /dev/null
+++ b/src/test/run-pass/integer-literal-radix.rs
@@ -0,0 +1,27 @@
+// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+pub fn main() {
+    let a = 0xBEEF;
+    let b = 0o755;
+    let c = 0b10101;
+    let d = -0xBEEF;
+    let e = -0o755;
+    let f = -0b10101;
+
+    assert_eq!(a, 48879);
+    assert_eq!(b, 493);
+    assert_eq!(c, 21);
+    assert_eq!(d, -48879);
+    assert_eq!(e, -493);
+    assert_eq!(f, -21);
+
+
+}