about summary refs log tree commit diff
path: root/src/libsyntax/parse/parser.rs
diff options
context:
space:
mode:
authorJeong YunWon <jeong@youknowone.org>2013-05-05 10:57:14 +0900
committerJeong YunWon <jeong@youknowone.org>2013-05-05 11:05:06 +0900
commitcb918e1a831782d6072a0b93dd57614cb9c2d961 (patch)
tree0d3a0ef0ddaaa451b3c61a66bcd2ebfa6de9845d /src/libsyntax/parse/parser.rs
parentd74ac9ea03eb8faab72ce48b89dd47a14f45982a (diff)
downloadrust-cb918e1a831782d6072a0b93dd57614cb9c2d961.tar.gz
rust-cb918e1a831782d6072a0b93dd57614cb9c2d961.zip
Allow non-literal static range pattern for match arms
Fix unintended error problem of:

static s: int = 1;
static e: int = 42;

fn main() {
    match 7 {
        s..e => (),
         ^~                 error: expected `=>` but found `..`
        _ => (),
    }
}
Diffstat (limited to 'src/libsyntax/parse/parser.rs')
-rw-r--r--src/libsyntax/parse/parser.rs10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index a6528160398..de88089b1bf 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -2383,7 +2383,13 @@ pub impl Parser {
                         can_be_enum_or_struct = false
                 }
 
-                if is_plain_ident(&*self.token) && !can_be_enum_or_struct {
+                if self.look_ahead(1) == token::DOTDOT {
+                    let start = self.parse_expr_res(RESTRICT_NO_BAR_OP);
+                    self.eat(&token::DOTDOT);
+                    let end = self.parse_expr_res(RESTRICT_NO_BAR_OP);
+                    pat = pat_range(start, end);
+                }
+                else if is_plain_ident(&*self.token) && !can_be_enum_or_struct {
                     let name = self.parse_path_without_tps();
                     let sub;
                     if self.eat(&token::AT) {
@@ -2392,7 +2398,7 @@ pub impl Parser {
                     } else {
                         // or just foo
                         sub = None;
-                    };
+                    }
                     pat = pat_ident(binding_mode, name, sub);
                 } else {
                     // parse an enum pat