Skip to content

Commit 55ee06b

Browse files
committed
libsyntax: Accept "1..3" as the preferred form of "1 to 3" in patterns
1 parent 36d8682 commit 55ee06b

File tree

4 files changed

+11
-10
lines changed

4 files changed

+11
-10
lines changed

src/libsyntax/parse/lexer.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,8 @@ fn scan_number(c: char, rdr: string_reader) -> token::token {
377377
}
378378
}
379379
let mut is_float = false;
380-
if rdr.curr == '.' && !(is_alpha(nextch(rdr)) || nextch(rdr) == '_') {
380+
if rdr.curr == '.' && !(is_alpha(nextch(rdr)) || nextch(rdr) == '_' ||
381+
nextch(rdr) == '.') {
381382
is_float = true;
382383
bump(rdr);
383384
let dec_part = scan_digits(rdr, 10u);

src/libsyntax/parse/parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1797,7 +1797,7 @@ class parser {
17971797
|| self.is_keyword(~"false")
17981798
{
17991799
let val = self.parse_expr_res(RESTRICT_NO_BAR_OP);
1800-
if self.eat_keyword(~"to") {
1800+
if self.eat_keyword(~"to") || self.eat(token::DOTDOT) {
18011801
let end = self.parse_expr_res(RESTRICT_NO_BAR_OP);
18021802
pat = pat_range(val, end);
18031803
} else {

src/libsyntax/print/pprust.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1512,7 +1512,7 @@ fn print_pat(s: ps, &&pat: @ast::pat) {
15121512
ast::pat_range(begin, end) => {
15131513
print_expr(s, begin);
15141514
space(s.s);
1515-
word_space(s, ~"to");
1515+
word(s.s, ~"..");
15161516
print_expr(s, end);
15171517
}
15181518
}

src/test/run-pass/alt-range.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
fn main() {
22
match 5u {
3-
1u to 5u => {}
3+
1u..5u => {}
44
_ => fail ~"should match range",
55
}
66
match 5u {
7-
6u to 7u => fail ~"shouldn't match range",
7+
6u..7u => fail ~"shouldn't match range",
88
_ => {}
99
}
1010
match check 5u {
1111
1u => fail ~"should match non-first range",
12-
2u to 6u => {}
12+
2u..6u => {}
1313
}
1414
match 'c' {
15-
'a' to 'z' => {}
15+
'a'..'z' => {}
1616
_ => fail ~"should suppport char ranges"
1717
}
1818
match -3 {
19-
-7 to 5 => {}
19+
-7..5 => {}
2020
_ => fail ~"should match signed range"
2121
}
2222
match 3.0 {
23-
1.0 to 5.0 => {}
23+
1.0..5.0 => {}
2424
_ => fail ~"should match float range"
2525
}
2626
match -1.5 {
27-
-3.6 to 3.6 => {}
27+
-3.6..3.6 => {}
2828
_ => fail ~"should match negative float range"
2929
}
3030
}

0 commit comments

Comments
 (0)