diff --git a/doc/po/ja/rust.md.po b/doc/po/ja/rust.md.po
index 0313a3379b787..42237b9d6cca3 100644
--- a/doc/po/ja/rust.md.po
+++ b/doc/po/ja/rust.md.po
@@ -678,6 +678,13 @@ msgid ""
"and continues as any mixture hex digits and underscores."
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 ""
@@ -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 076ef7f245263..26dc7bf0db866 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 31056378a48dc..9acefdf821568 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: ' * '
@@ -678,6 +678,13 @@ msgid ""
"and continues as any mixture hex digits and underscores."
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 ""
@@ -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 fc0403da2182b..a9c93aa6a8ba5 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 1e1a21c8ee903..389ea58ee1566 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 fff5909dc8988..5d23300492955 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 1c1bb0a00121a..b8841ebe568e9 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]
+
+ [0-7]
+
+
((?<=\.\.)|(?<![\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 17e3e06db3588..5efd393fc3585 100644
--- a/src/etc/kate/rust.xml
+++ b/src/etc/kate/rust.xml
@@ -199,6 +199,7 @@
+
diff --git a/src/etc/vim/syntax/rust.vim b/src/etc/vim/syntax/rust.vim
index a0a239284ceb7..e5ff089e2e189 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 49445312a12f6..06a2c557e4228 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 0000000000000..511116b1c559c
--- /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 or the MIT license
+// , 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 0000000000000..0423e7b89f077
--- /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 or the MIT license
+// , 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);
+
+
+}