about summary refs log tree commit diff
path: root/src/comp/syntax
diff options
context:
space:
mode:
authorJosh Matthews <josh@joshmatthews.net>2011-09-21 03:00:32 -0400
committerMarijn Haverbeke <marijnh@gmail.com>2011-09-21 09:36:12 +0200
commitce0f054f9d56df4e60291fc2e1b89ce979cf374f (patch)
treec468615e0a4e1ef007a5330fd0b37fb6669de8b9 /src/comp/syntax
parente6a84f252ab7a016dd923adbf31e8c86deab1d72 (diff)
downloadrust-ce0f054f9d56df4e60291fc2e1b89ce979cf374f.tar.gz
rust-ce0f054f9d56df4e60291fc2e1b89ce979cf374f.zip
Implement pattern ranges for all numeric types.
Diffstat (limited to 'src/comp/syntax')
-rw-r--r--src/comp/syntax/ast.rs1
-rw-r--r--src/comp/syntax/ast_util.rs3
-rw-r--r--src/comp/syntax/fold.rs1
-rw-r--r--src/comp/syntax/parse/parser.rs10
-rw-r--r--src/comp/syntax/print/pprust.rs6
5 files changed, 18 insertions, 3 deletions
diff --git a/src/comp/syntax/ast.rs b/src/comp/syntax/ast.rs
index ad6aacb1549..a409f7c2437 100644
--- a/src/comp/syntax/ast.rs
+++ b/src/comp/syntax/ast.rs
@@ -92,6 +92,7 @@ tag pat_ {
     pat_rec([field_pat], bool);
     pat_tup([@pat]);
     pat_box(@pat);
+    pat_range(@lit, @lit);
 }
 
 tag mutability { mut; imm; maybe_mut; }
diff --git a/src/comp/syntax/ast_util.rs b/src/comp/syntax/ast_util.rs
index 8350ce9a8bb..d94258a6ac7 100644
--- a/src/comp/syntax/ast_util.rs
+++ b/src/comp/syntax/ast_util.rs
@@ -69,7 +69,7 @@ iter pat_bindings(pat: @pat) -> @pat {
         for elt in elts { for each b in pat_bindings(elt) { put b; } }
       }
       pat_box(sub) { for each b in pat_bindings(sub) { put b; } }
-      pat_wild. | pat_lit(_) { }
+      pat_wild. | pat_lit(_) | pat_range(_, _) { }
     }
 }
 
@@ -229,3 +229,4 @@ fn ret_by_ref(style: ret_style) -> bool {
 // buffer-file-coding-system: utf-8-unix
 // compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
 // End:
+
diff --git a/src/comp/syntax/fold.rs b/src/comp/syntax/fold.rs
index c53176e24fb..68c12153873 100644
--- a/src/comp/syntax/fold.rs
+++ b/src/comp/syntax/fold.rs
@@ -291,6 +291,7 @@ fn noop_fold_pat(p: pat_, fld: ast_fold) -> pat_ {
           }
           pat_tup(elts) { pat_tup(vec::map(fld.fold_pat, elts)) }
           pat_box(inner) { pat_box(fld.fold_pat(inner)) }
+          pat_range(_, _) { p }
         };
 }
 
diff --git a/src/comp/syntax/parse/parser.rs b/src/comp/syntax/parse/parser.rs
index 6869dc6501d..efed1380a23 100644
--- a/src/comp/syntax/parse/parser.rs
+++ b/src/comp/syntax/parse/parser.rs
@@ -1494,8 +1494,14 @@ fn parse_pat(p: parser) -> @ast::pat {
       tok {
         if !is_ident(tok) || is_word(p, "true") || is_word(p, "false") {
             let lit = parse_lit(p);
-            hi = lit.span.hi;
-            pat = ast::pat_lit(@lit);
+            if eat_word(p, "to") {
+                let end = parse_lit(p);
+                hi = end.span.hi;
+                pat = ast::pat_range(@lit, @end);
+            } else {
+                hi = lit.span.hi;
+                pat = ast::pat_lit(@lit);
+            }
         } else if is_plain_ident(p) &&
                       alt p.look_ahead(1u) {
                         token::DOT. | token::LPAREN. | token::LBRACKET. {
diff --git a/src/comp/syntax/print/pprust.rs b/src/comp/syntax/print/pprust.rs
index 48031a295db..3bf5b0310c9 100644
--- a/src/comp/syntax/print/pprust.rs
+++ b/src/comp/syntax/print/pprust.rs
@@ -1113,6 +1113,12 @@ fn print_pat(s: ps, pat: @ast::pat) {
         pclose(s);
       }
       ast::pat_box(inner) { word(s.s, "@"); print_pat(s, inner); }
+      ast::pat_range(begin, end) {
+        print_literal(s, begin);
+        space(s.s);
+        word_space(s, "to");
+        print_literal(s, end);
+      }
     }
     s.ann.post(ann_node);
 }