mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-26 14:43:24 +00:00
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.
This commit is contained in:
commit
f00bb2ec04
@ -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 ""
|
||||
|
@ -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."
|
||||
|
@ -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 ""
|
||||
|
@ -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."
|
||||
|
@ -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
|
||||
~~~~
|
||||
|
||||
|
@ -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.
|
||||
|
@ -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">
|
||||
((?<=\.\.)|(?<![\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\.].)|(?=\.\.))
|
||||
|
@ -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"/>
|
||||
|
@ -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
|
||||
|
@ -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"),
|
||||
_ => ()
|
||||
|
17
src/test/compile-fail/no-oct-float-literal.rs
Normal file
17
src/test/compile-fail/no-oct-float-literal.rs
Normal file
@ -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;
|
||||
}
|
27
src/test/run-pass/integer-literal-radix.rs
Normal file
27
src/test/run-pass/integer-literal-radix.rs
Normal file
@ -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);
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user