Skip to content

Commit f00bb2e

Browse files
committed
auto merge of #10243 : mattcarberry/rust/master, r=brson
Associated with Issue #6563. Useful for Apollo Guidance Computer simulation, Unix file system permissions, and maybe one or two other things.
2 parents a0593e5 + 6eba332 commit f00bb2e

File tree

12 files changed

+91
-5
lines changed

12 files changed

+91
-5
lines changed

doc/po/ja/rust.md.po

+8
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,13 @@ msgid ""
678678
"and continues as any mixture hex digits and underscores."
679679
msgstr ""
680680

681+
#. type: Bullet: ' * '
682+
#: doc/rust.md:326
683+
msgid ""
684+
"An _octal literal_ starts with the character sequence `U+0030` `U+006F` (`0o`) "
685+
"and continues as any mixture octal digits and underscores."
686+
msgstr ""
687+
681688
#. type: Bullet: ' * '
682689
#: doc/rust.md:326
683690
msgid ""
@@ -740,6 +747,7 @@ msgid ""
740747
"123u; // type uint\n"
741748
"123_u; // type uint\n"
742749
"0xff_u8; // type u8\n"
750+
"0o70_i16; // type i16\n"
743751
"0b1111_1111_1001_0000_i32; // type i32\n"
744752
"~~~~\n"
745753
msgstr ""

doc/po/ja/tutorial.md.po

+1-1
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,7 @@ msgstr "## プリミティブ型とリテラル"
849849
msgid ""
850850
"There are general signed and unsigned integer types, `int` and `uint`, as "
851851
"well as 8-, 16-, 32-, and 64-bit variants, `i8`, `u16`, etc. Integers can "
852-
"be written in decimal (`144`), hexadecimal (`0x90`), or binary "
852+
"be written in decimal (`144`), hexadecimal (`0x90`), octal (`0o70`), or binary "
853853
"(`0b10010000`) base. Each integral type has a corresponding literal suffix "
854854
"that can be used to indicate the type of a literal: `i` for `int`, `u` for "
855855
"`uint`, `i8` for the `i8` type."

doc/po/rust.md.pot

+9-1
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ msgstr ""
661661

662662
#. type: Plain text
663663
#: doc/rust.md:319
664-
msgid "An _integer literal_ has one of three forms:"
664+
msgid "An _integer literal_ has one of four forms:"
665665
msgstr ""
666666

667667
#. type: Bullet: ' * '
@@ -678,6 +678,13 @@ msgid ""
678678
"and continues as any mixture hex digits and underscores."
679679
msgstr ""
680680

681+
#. type: Bullet: ' * '
682+
#: doc/rust.md:326
683+
msgid ""
684+
"An _octal literal_ starts with the character sequence `U+0030` `U+006F` (`0o`) "
685+
"and continues as any mixture octal digits and underscores."
686+
msgstr ""
687+
681688
#. type: Bullet: ' * '
682689
#: doc/rust.md:326
683690
msgid ""
@@ -740,6 +747,7 @@ msgid ""
740747
"123u; // type uint\n"
741748
"123_u; // type uint\n"
742749
"0xff_u8; // type u8\n"
750+
"0o70_i16; // type i16\n"
743751
"0b1111_1111_1001_0000_i32; // type i32\n"
744752
"~~~~\n"
745753
msgstr ""

doc/po/tutorial.md.pot

+1-1
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ msgstr ""
646646
msgid ""
647647
"There are general signed and unsigned integer types, `int` and `uint`, as "
648648
"well as 8-, 16-, 32-, and 64-bit variants, `i8`, `u16`, etc. Integers can "
649-
"be written in decimal (`144`), hexadecimal (`0x90`), or binary "
649+
"be written in decimal (`144`), hexadecimal (`0x90`), octal (`0o70`), or binary "
650650
"(`0b10010000`) base. Each integral type has a corresponding literal suffix "
651651
"that can be used to indicate the type of a literal: `i` for `int`, `u` for "
652652
"`uint`, `i8` for the `i8` type."

doc/rust.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -340,12 +340,14 @@ as they are differentiated by suffixes.
340340

341341
##### Integer literals
342342

343-
An _integer literal_ has one of three forms:
343+
An _integer literal_ has one of four forms:
344344

345345
* A _decimal literal_ starts with a *decimal digit* and continues with any
346346
mixture of *decimal digits* and _underscores_.
347347
* A _hex literal_ starts with the character sequence `U+0030` `U+0078`
348348
(`0x`) and continues as any mixture hex digits and underscores.
349+
* An _octal literal_ starts with the character sequence `U+0030` `U+006F`
350+
(`0o`) and continues as any mixture octal digits and underscores.
349351
* A _binary literal_ starts with the character sequence `U+0030` `U+0062`
350352
(`0b`) and continues as any mixture binary digits and underscores.
351353

@@ -376,6 +378,7 @@ Examples of integer literals of various forms:
376378
123u; // type uint
377379
123_u; // type uint
378380
0xff_u8; // type u8
381+
0o70_i16; // type i16
379382
0b1111_1111_1001_0000_i32; // type i32
380383
~~~~
381384

doc/tutorial.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ fn is_four(x: int) -> bool {
305305

306306
There are general signed and unsigned integer types, `int` and `uint`,
307307
as well as 8-, 16-, 32-, and 64-bit variants, `i8`, `u16`, etc.
308-
Integers can be written in decimal (`144`), hexadecimal (`0x90`), or
308+
Integers can be written in decimal (`144`), hexadecimal (`0x90`), octal (`0o70`), or
309309
binary (`0b10010000`) base. Each integral type has a corresponding literal
310310
suffix that can be used to indicate the type of a literal: `i` for `int`,
311311
`u` for `uint`, `i8` for the `i8` type.

src/etc/gedit/share/gtksourceview-3.0/language-specs/rust.lang

+5
Original file line numberDiff line numberDiff line change
@@ -224,13 +224,18 @@
224224
[0-9a-fA-F]
225225
</define-regex>
226226

227+
<define-regex id="oct_digit" extended="true">
228+
[0-7]
229+
</define-regex>
230+
227231
<context id="number" style-ref="number">
228232
<match extended="true">
229233
((?&lt;=\.\.)|(?&lt;![\w\.]))
230234
(
231235
[1-9][0-9_]*\%{num_suffix}?|
232236
0[0-9_]*\%{num_suffix}?|
233237
0b[01_]+\%{int_suffix}?|
238+
0o(\%{oct_digit}|_)+\%{int_suffix}?|
234239
0x(\%{hex_digit}|_)+\%{int_suffix}?
235240
)
236241
((?![\w\.].)|(?=\.\.))

src/etc/kate/rust.xml

+1
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@
199199
<Detect2Chars char="/" char1="/" attribute="Comment" context="Commentar 1"/>
200200
<Detect2Chars char="/" char1="*" attribute="Comment" context="Commentar 2" beginRegion="Comment"/>
201201
<RegExpr String="0x[0-9a-fA-F_]+&rustIntSuf;" attribute="Number" context="#stay"/>
202+
<RegExpr String="0o[0-7_]+&rustIntSuf;" attribute="Number" context="#stay"/>
202203
<RegExpr String="0b[0-1_]+&rustIntSuf;" attribute="Number" context="#stay"/>
203204
<RegExpr String="[0-9][0-9_]*\.[0-9_]*([eE][+-]?[0-9_]+)?(f32|f64|f)?" attribute="Number" context="#stay"/>
204205
<RegExpr String="[0-9][0-9_]*&rustIntSuf;" attribute="Number" context="#stay"/>

src/etc/vim/syntax/rust.vim

+4
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ syn match rustNumber display "\<[0-9][0-9_]*\(i\|i8\|i16\|i32\|i64\)\>"
161161
syn match rustHexNumber display "\<0x[a-fA-F0-9_]\+\>"
162162
syn match rustHexNumber display "\<0x[a-fA-F0-9_]\+\(u\|u8\|u16\|u32\|u64\)\>"
163163
syn match rustHexNumber display "\<0x[a-fA-F0-9_]\+\(i8\|i16\|i32\|i64\)\>"
164+
syn match rustOctNumber display "\<0o[0-7_]\+\>"
165+
syn match rustOctNumber display "\<0o[0-7_]\+\(u\|u8\|u16\|u32\|u64\)\>"
166+
syn match rustOctNumber display "\<0o[0-7_]\+\(i8\|i16\|i32\|i64\)\>"
164167
syn match rustBinNumber display "\<0b[01_]\+\>"
165168
syn match rustBinNumber display "\<0b[01_]\+\(u\|u8\|u16\|u32\|u64\)\>"
166169
syn match rustBinNumber display "\<0b[01_]\+\(i8\|i16\|i32\|i64\)\>"
@@ -198,6 +201,7 @@ syn region rustFoldBraces start="{" end="}" transparent fold
198201

199202
" Default highlighting {{{1
200203
hi def link rustHexNumber rustNumber
204+
hi def link rustOctNumber rustNumber
201205
hi def link rustBinNumber rustNumber
202206
hi def link rustIdentifierPrime rustIdentifier
203207
hi def link rustTrait rustType

src/libsyntax/parse/lexer.rs

+13
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,11 @@ fn hex_digit_val(c: char) -> int {
276276
fail!();
277277
}
278278

279+
fn oct_digit_val(c: char) -> int {
280+
if in_range(c, '0', '7') { return (c as int) - ('0' as int); }
281+
fail!();
282+
}
283+
279284
fn bin_digit_value(c: char) -> int { if c == '0' { return 0; } return 1; }
280285

281286
pub fn is_whitespace(c: char) -> bool {
@@ -293,6 +298,8 @@ fn is_hex_digit(c: char) -> bool {
293298
in_range(c, 'A', 'F');
294299
}
295300

301+
fn is_oct_digit(c: char) -> bool { return in_range(c, '0', '7'); }
302+
296303
fn is_bin_digit(c: char) -> bool { return c == '0' || c == '1'; }
297304

298305
// EFFECT: eats whitespace and comments.
@@ -464,6 +471,10 @@ fn scan_number(c: char, rdr: @mut StringReader) -> token::Token {
464471
bump(rdr);
465472
bump(rdr);
466473
base = 16u;
474+
} else if c == '0' && n == 'o' {
475+
bump(rdr);
476+
bump(rdr);
477+
base = 8u;
467478
} else if c == '0' && n == 'b' {
468479
bump(rdr);
469480
bump(rdr);
@@ -529,6 +540,8 @@ fn scan_number(c: char, rdr: @mut StringReader) -> token::Token {
529540
match base {
530541
16u => fatal_span(rdr, start_bpos, rdr.last_pos,
531542
~"hexadecimal float literal is not supported"),
543+
8u => fatal_span(rdr, start_bpos, rdr.last_pos,
544+
~"octal float literal is not supported"),
532545
2u => fatal_span(rdr, start_bpos, rdr.last_pos,
533546
~"binary float literal is not supported"),
534547
_ => ()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// error-pattern:octal float literal is not supported
12+
13+
fn main() {
14+
0o123f64;
15+
0o123.456;
16+
0o123p4f;
17+
}
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
pub fn main() {
12+
let a = 0xBEEF;
13+
let b = 0o755;
14+
let c = 0b10101;
15+
let d = -0xBEEF;
16+
let e = -0o755;
17+
let f = -0b10101;
18+
19+
assert_eq!(a, 48879);
20+
assert_eq!(b, 493);
21+
assert_eq!(c, 21);
22+
assert_eq!(d, -48879);
23+
assert_eq!(e, -493);
24+
assert_eq!(f, -21);
25+
26+
27+
}

0 commit comments

Comments
 (0)