Remove the 'to' keyword

This commit is contained in:
Brian Anderson 2012-09-01 18:38:05 -07:00
parent d777e51333
commit 80c4f74c29
13 changed files with 2418 additions and 2419 deletions

View File

@ -2211,14 +2211,14 @@ fn main() {
~~~~ ~~~~
Multiple match patterns may be joined with the `|` operator. A Multiple match patterns may be joined with the `|` operator. A
range of values may be specified with `to`. For example: range of values may be specified with `..`. For example:
~~~~ ~~~~
# let x = 2; # let x = 2;
let message = match x { let message = match x {
0 | 1 => ~"not many", 0 | 1 => ~"not many",
2 to 9 => ~"a few", 2 .. 9 => ~"a few",
_ => ~"lots" _ => ~"lots"
}; };
~~~~ ~~~~

View File

@ -120,9 +120,9 @@ pure fn is_digit(c: char) -> bool {
*/ */
pure fn to_digit(c: char, radix: uint) -> Option<uint> { pure fn to_digit(c: char, radix: uint) -> Option<uint> {
let val = match c { let val = match c {
'0' to '9' => c as uint - ('0' as uint), '0' .. '9' => c as uint - ('0' as uint),
'a' to 'z' => c as uint + 10u - ('a' as uint), 'a' .. 'z' => c as uint + 10u - ('a' as uint),
'A' to 'Z' => c as uint + 10u - ('A' as uint), 'A' .. 'Z' => c as uint + 10u - ('A' as uint),
_ => return None _ => return None
}; };
if val < radix { Some(val) } if val < radix { Some(val) }
@ -171,7 +171,7 @@ fn escape_default(c: char) -> ~str {
'\\' => ~"\\\\", '\\' => ~"\\\\",
'\'' => ~"\\'", '\'' => ~"\\'",
'"' => ~"\\\"", '"' => ~"\\\"",
'\x20' to '\x7e' => str::from_char(c), '\x20' .. '\x7e' => str::from_char(c),
_ => escape_unicode(c) _ => escape_unicode(c)
} }
} }

View File

@ -263,7 +263,7 @@ fn from_str(num: &str) -> Option<float> {
//The string must start with one of the following characters. //The string must start with one of the following characters.
match str::char_at(num, 0u) { match str::char_at(num, 0u) {
'-' | '+' | '0' to '9' | '.' => (), '-' | '+' | '0' .. '9' | '.' => (),
_ => return None _ => return None
} }
@ -286,7 +286,7 @@ fn from_str(num: &str) -> Option<float> {
c = char_range.ch; c = char_range.ch;
pos = char_range.next; pos = char_range.next;
match c { match c {
'0' to '9' => { '0' .. '9' => {
total = total * 10f; total = total * 10f;
total += ((c as int) - ('0' as int)) as float; total += ((c as int) - ('0' as int)) as float;
} }

File diff suppressed because it is too large Load Diff

View File

@ -267,7 +267,7 @@ impl Parser {
'n' => self.parse_ident(~"ull", Null), 'n' => self.parse_ident(~"ull", Null),
't' => self.parse_ident(~"rue", Boolean(true)), 't' => self.parse_ident(~"rue", Boolean(true)),
'f' => self.parse_ident(~"alse", Boolean(false)), 'f' => self.parse_ident(~"alse", Boolean(false)),
'0' to '9' | '-' => self.parse_number(), '0' .. '9' | '-' => self.parse_number(),
'"' => match self.parse_str() { '"' => match self.parse_str() {
Ok(s) => Ok(String(s)), Ok(s) => Ok(String(s)),
Err(e) => Err(e) Err(e) => Err(e)
@ -330,14 +330,14 @@ impl Parser {
// There can be only one leading '0'. // There can be only one leading '0'.
match self.ch { match self.ch {
'0' to '9' => return self.error(~"invalid number"), '0' .. '9' => return self.error(~"invalid number"),
_ => () _ => ()
} }
} }
'1' to '9' => { '1' .. '9' => {
while !self.eof() { while !self.eof() {
match self.ch { match self.ch {
'0' to '9' => { '0' .. '9' => {
res *= 10f; res *= 10f;
res += ((self.ch as int) - ('0' as int)) as float; res += ((self.ch as int) - ('0' as int)) as float;
@ -358,7 +358,7 @@ impl Parser {
// Make sure a digit follows the decimal place. // Make sure a digit follows the decimal place.
match self.ch { match self.ch {
'0' to '9' => (), '0' .. '9' => (),
_ => return self.error(~"invalid number") _ => return self.error(~"invalid number")
} }
@ -366,7 +366,7 @@ impl Parser {
let mut dec = 1f; let mut dec = 1f;
while !self.eof() { while !self.eof() {
match self.ch { match self.ch {
'0' to '9' => { '0' .. '9' => {
dec /= 10f; dec /= 10f;
res += (((self.ch as int) - ('0' as int)) as float) * dec; res += (((self.ch as int) - ('0' as int)) as float) * dec;
@ -394,13 +394,13 @@ impl Parser {
// Make sure a digit follows the exponent place. // Make sure a digit follows the exponent place.
match self.ch { match self.ch {
'0' to '9' => (), '0' .. '9' => (),
_ => return self.error(~"invalid number") _ => return self.error(~"invalid number")
} }
while !self.eof() { while !self.eof() {
match self.ch { match self.ch {
'0' to '9' => { '0' .. '9' => {
exp *= 10u; exp *= 10u;
exp += (self.ch as uint) - ('0' as uint); exp += (self.ch as uint) - ('0' as uint);
@ -443,7 +443,7 @@ impl Parser {
let mut n = 0u; let mut n = 0u;
while i < 4u { while i < 4u {
match self.next_char() { match self.next_char() {
'0' to '9' => { '0' .. '9' => {
n = n * 16u + (self.ch as uint) n = n * 16u + (self.ch as uint)
- ('0' as uint); - ('0' as uint);
}, },

View File

@ -50,9 +50,9 @@ fn encode_inner(s: ~str, full_url: bool) -> ~str {
let ch = rdr.read_byte() as char; let ch = rdr.read_byte() as char;
match ch { match ch {
// unreserved: // unreserved:
'A' to 'Z' | 'A' .. 'Z' |
'a' to 'z' | 'a' .. 'z' |
'0' to '9' | '0' .. '9' |
'-' | '.' | '_' | '~' => { '-' | '.' | '_' | '~' => {
str::push_char(out, ch); str::push_char(out, ch);
} }
@ -162,7 +162,7 @@ fn encode_plus(s: ~str) -> ~str {
while !rdr.eof() { while !rdr.eof() {
let ch = rdr.read_byte() as char; let ch = rdr.read_byte() as char;
match ch { match ch {
'A' to 'Z' | 'a' to 'z' | '0' to '9' | '_' | '.' | '-' => { 'A' .. 'Z' | 'a' .. 'z' | '0' .. '9' | '_' | '.' | '-' => {
str::push_char(out, ch); str::push_char(out, ch);
} }
' ' => str::push_char(out, '+'), ' ' => str::push_char(out, '+'),
@ -340,8 +340,8 @@ fn query_to_str(query: Query) -> ~str {
fn get_scheme(rawurl: ~str) -> result::Result<(~str, ~str), @~str> { fn get_scheme(rawurl: ~str) -> result::Result<(~str, ~str), @~str> {
for str::each_chari(rawurl) |i,c| { for str::each_chari(rawurl) |i,c| {
match c { match c {
'A' to 'Z' | 'a' to 'z' => again, 'A' .. 'Z' | 'a' .. 'z' => again,
'0' to '9' | '+' | '-' | '.' => { '0' .. '9' | '+' | '-' | '.' => {
if i == 0 { if i == 0 {
return result::Err(@~"url: Scheme must begin with a letter."); return result::Err(@~"url: Scheme must begin with a letter.");
} }
@ -415,13 +415,13 @@ fn get_authority(rawurl: ~str) ->
// deal with input class first // deal with input class first
match c { match c {
'0' to '9' => (), '0' .. '9' => (),
'A' to 'F' | 'a' to 'f' => { 'A' .. 'F' | 'a' .. 'f' => {
if in == Digit { if in == Digit {
in = Hex; in = Hex;
} }
} }
'G' to 'Z' | 'g' to 'z' | '-' | '.' | '_' | '~' | '%' | 'G' .. 'Z' | 'g' .. 'z' | '-' | '.' | '_' | '~' | '%' |
'&' |'\'' | '(' | ')' | '+' | '!' | '*' | ',' | ';' | '=' => { '&' |'\'' | '(' | ')' | '+' | '!' | '*' | ',' | ';' | '=' => {
in = Unreserved; in = Unreserved;
} }
@ -558,7 +558,7 @@ fn get_path(rawurl: ~str, authority : bool) ->
let mut end = len; let mut end = len;
for str::each_chari(rawurl) |i,c| { for str::each_chari(rawurl) |i,c| {
match c { match c {
'A' to 'Z' | 'a' to 'z' | '0' to '9' | '&' |'\'' | '(' | ')' | '.' 'A' .. 'Z' | 'a' .. 'z' | '0' .. '9' | '&' |'\'' | '(' | ')' | '.'
| '@' | ':' | '%' | '/' | '+' | '!' | '*' | ',' | ';' | '=' | '@' | ':' | '%' | '/' | '+' | '!' | '*' | ',' | ';' | '='
| '_' | '-' => { | '_' | '-' => {
again; again;

View File

@ -215,7 +215,7 @@ fn strptime(s: &str, format: &str) -> Result<Tm, ~str> {
pos = next; pos = next;
match ch { match ch {
'0' to '9' => { '0' .. '9' => {
value = value * 10_i32 + (ch as i32 - '0' as i32); value = value * 10_i32 + (ch as i32 - '0' as i32);
} }
' ' if ws => (), ' ' if ws => (),

View File

@ -1869,7 +1869,7 @@ struct parser {
|| self.is_keyword(~"false") || self.is_keyword(~"false")
{ {
let val = self.parse_expr_res(RESTRICT_NO_BAR_OP); let val = self.parse_expr_res(RESTRICT_NO_BAR_OP);
if self.eat_keyword(~"to") || self.eat(token::DOTDOT) { if self.eat(token::DOTDOT) {
let end = self.parse_expr_res(RESTRICT_NO_BAR_OP); let end = self.parse_expr_res(RESTRICT_NO_BAR_OP);
pat = pat_range(val, end); pat = pat_range(val, end);
} else { } else {

View File

@ -389,7 +389,6 @@ fn contextual_keyword_table() -> hashmap<~str, ()> {
~"of", ~"of",
~"priv", ~"pub", ~"priv", ~"pub",
~"self", ~"send", ~"static", ~"self", ~"send", ~"static",
~"to",
~"use", ~"use",
~"with" ~"with"
]; ];

View File

@ -547,9 +547,9 @@ fn sanitize(s: ~str) -> ~str {
',' => result += ~"_", ',' => result += ~"_",
'{' | '(' => result += ~"_of_", '{' | '(' => result += ~"_of_",
'a' to 'z' 'a' .. 'z'
| 'A' to 'Z' | 'A' .. 'Z'
| '0' to '9' | '0' .. '9'
| '_' => str::push_char(result,c), | '_' => str::push_char(result,c),
_ => { _ => {
if c > 'z' && char::is_XID_continue(c) { if c > 'z' && char::is_XID_continue(c) {

View File

@ -6,31 +6,31 @@
fn main() { fn main() {
match 5u { match 5u {
1u to 10u => { } 1u .. 10u => { }
5u to 6u => { } 5u .. 6u => { }
_ => {} _ => {}
}; };
match 5u { match 5u {
3u to 6u => { } 3u .. 6u => { }
4u to 6u => { } 4u .. 6u => { }
_ => {} _ => {}
}; };
match 5u { match 5u {
4u to 6u => { } 4u .. 6u => { }
4u to 6u => { } 4u .. 6u => { }
_ => {} _ => {}
}; };
match 'c' { match 'c' {
'A' to 'z' => {} 'A' .. 'z' => {}
'a' to 'z' => {} 'a' .. 'z' => {}
_ => {} _ => {}
}; };
match 1.0 { match 1.0 {
0.01 to 6.5 => {} 0.01 .. 6.5 => {}
0.02 => {} 0.02 => {}
_ => {} _ => {}
}; };

View File

@ -4,16 +4,16 @@
fn main() { fn main() {
match 5u { match 5u {
6u to 1u => { } 6u .. 1u => { }
_ => { } _ => { }
}; };
match "wow" { match "wow" {
"bar" to "foo" => { } "bar" .. "foo" => { }
}; };
match 5u { match 5u {
'c' to 100u => { } 'c' .. 100u => { }
_ => { } _ => { }
}; };
} }

View File

@ -1,21 +1,21 @@
fn main() { fn main() {
let x = 2; let x = 2;
let x_message = match x { let x_message = match x {
0 to 1 => { ~"not many" } 0 .. 1 => { ~"not many" }
_ => { ~"lots" } _ => { ~"lots" }
}; };
assert x_message == ~"lots"; assert x_message == ~"lots";
let y = 2i; let y = 2i;
let y_message = match y { let y_message = match y {
0 to 1 => { ~"not many" } 0 .. 1 => { ~"not many" }
_ => { ~"lots" } _ => { ~"lots" }
}; };
assert y_message == ~"lots"; assert y_message == ~"lots";
let z = 1u64; let z = 1u64;
let z_message = match z { let z_message = match z {
0 to 1 => { ~"not many" } 0 .. 1 => { ~"not many" }
_ => { ~"lots" } _ => { ~"lots" }
}; };
assert z_message == ~"not many"; assert z_message == ~"not many";