about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2012-09-14 15:20:09 -0700
committerNiko Matsakis <niko@alum.mit.edu>2012-09-14 15:22:15 -0700
commit7107b4eff51e58aa1ae5e30b073b4d788b13a2cb (patch)
treec2a529a20d4ba0986ce75ac1e4234be46e77c820 /src/libsyntax
parent34cece99cce373546d62aed06a7ec55d04aaa124 (diff)
downloadrust-7107b4eff51e58aa1ae5e30b073b4d788b13a2cb.tar.gz
rust-7107b4eff51e58aa1ae5e30b073b4d788b13a2cb.zip
Have parser recognize static, self region.
Fixes a bug in methods that &self couldn't be referenced in the
body. Also fixes #2479.
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/ast.rs7
-rw-r--r--src/libsyntax/parse/parser.rs19
-rw-r--r--src/libsyntax/print/pprust.rs48
3 files changed, 41 insertions, 33 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs
index 38eccd3593f..54c8acf7626 100644
--- a/src/libsyntax/ast.rs
+++ b/src/libsyntax/ast.rs
@@ -1047,7 +1047,12 @@ impl prim_ty : cmp::Eq {
 type region = {id: node_id, node: region_};
 
 #[auto_serialize]
-enum region_ { re_anon, re_named(ident) }
+enum region_ {
+    re_anon,
+    re_static,
+    re_self,
+    re_named(ident)
+}
 
 #[auto_serialize]
 enum ty_ {
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index c96cfdfe6bc..fa506a062b4 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -4,7 +4,7 @@ use result::Result;
 use either::{Either, Left, Right};
 use std::map::{HashMap, str_hash};
 use token::{can_begin_expr, is_ident, is_ident_or_path, is_plain_ident,
-               INTERPOLATED};
+            INTERPOLATED, special_idents};
 use codemap::{span,fss_none};
 use util::interner::interner;
 use ast_util::{spanned, respan, mk_sp, ident_to_path, operator_prec};
@@ -51,7 +51,8 @@ use ast::{_mod, add, alt_check, alt_exhaustive, arg, arm, attribute,
              pat_ident, pat_lit, pat_range, pat_rec, pat_region, pat_struct,
              pat_tup, pat_uniq, pat_wild, path, private, proto, proto_bare,
              proto_block, proto_box, proto_uniq, provided, public, pure_fn,
-             purity, re_anon, re_named, region, rem, required, ret_style,
+             purity, re_static, re_self, re_anon, re_named, region,
+             rem, required, ret_style,
              return_val, self_ty, shl, shr, stmt, stmt_decl, stmt_expr,
              stmt_semi, struct_def, struct_field, struct_variant_kind,
              subtract, sty_box, sty_by_ref, sty_region, sty_static, sty_uniq,
@@ -432,8 +433,10 @@ impl parser {
 
     fn region_from_name(s: Option<ident>) -> @region {
         let r = match s {
-          Some (id) => re_named(id),
-          None => re_anon
+            Some(id) if id == special_idents::static => ast::re_static,
+            Some(id) if id == special_idents::self_ => re_self,
+            Some(id) => re_named(id),
+            None => re_anon
         };
 
         @{id: self.get_id(), node: r}
@@ -614,7 +617,7 @@ impl parser {
                 let name = self.parse_value_ident();
                 self.bump();
                 name
-            } else { token::special_idents::invalid }
+            } else { special_idents::invalid }
         };
 
         let t = self.parse_ty(false);
@@ -2388,7 +2391,7 @@ impl parser {
 
     fn is_self_ident() -> bool {
         match self.token {
-          token::IDENT(id, false) if id == token::special_idents::self_
+          token::IDENT(id, false) if id == special_idents::self_
             => true,
           _ => false
         }
@@ -2603,7 +2606,7 @@ impl parser {
 
         // This is a new-style impl declaration.
         // XXX: clownshoes
-        let ident = token::special_idents::clownshoes_extensions;
+        let ident = special_idents::clownshoes_extensions;
 
         // Parse the type.
         let ty = self.parse_ty(false);
@@ -3019,7 +3022,7 @@ impl parser {
                 }
 
                 (ast::anonymous,
-                 token::special_idents::clownshoes_foreign_mod)
+                 special_idents::clownshoes_foreign_mod)
             }
         };
 
diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs
index 49133242d54..a4e7d12bd21 100644
--- a/src/libsyntax/print/pprust.rs
+++ b/src/libsyntax/print/pprust.rs
@@ -328,14 +328,24 @@ fn print_foreign_mod(s: ps, nmod: ast::foreign_mod,
     for nmod.items.each |item| { print_foreign_item(s, item); }
 }
 
-fn print_region(s: ps, region: @ast::region) {
+fn print_region(s: ps, region: @ast::region, sep: ~str) {
     match region.node {
-      ast::re_anon => word_space(s, ~"&"),
-      ast::re_named(name) => {
-        word(s.s, ~"&");
-        print_ident(s, name);
-      }
+        ast::re_anon => {
+            word_space(s, ~"&");
+            return;
+        }
+        ast::re_static => {
+            word_space(s, ~"&static")
+        }
+        ast::re_self => {
+            word_space(s, ~"&self")
+        }
+        ast::re_named(name) => {
+            word(s.s, ~"&");
+            print_ident(s, name);
+        }
     }
+    word(s.s, sep);
 }
 
 fn print_type(s: ps, &&ty: @ast::ty) {
@@ -362,11 +372,8 @@ fn print_type_ex(s: ps, &&ty: @ast::ty, print_colons: bool) {
       }
       ast::ty_ptr(mt) => { word(s.s, ~"*"); print_mt(s, mt); }
       ast::ty_rptr(region, mt) => {
-        match region.node {
-          ast::re_anon => word(s.s, ~"&"),
-          _ => { print_region(s, region); word(s.s, ~"/"); }
-        }
-        print_mt(s, mt);
+          print_region(s, region, ~"/");
+          print_mt(s, mt);
       }
       ast::ty_rec(fields) => {
         word(s.s, ~"{");
@@ -961,18 +968,11 @@ fn print_mac(s: ps, m: ast::mac) {
 
 fn print_vstore(s: ps, t: ast::vstore) {
     match t {
-      ast::vstore_fixed(Some(i)) => word(s.s, fmt!("%u", i)),
-      ast::vstore_fixed(None) => word(s.s, ~"_"),
-      ast::vstore_uniq => word(s.s, ~"~"),
-      ast::vstore_box => word(s.s, ~"@"),
-      ast::vstore_slice(r) => match r.node {
-        ast::re_anon => word(s.s, ~"&"),
-        ast::re_named(name) => {
-            word(s.s, ~"&");
-            print_ident(s, name);
-            word(s.s, ~".");
-        }
-      }
+        ast::vstore_fixed(Some(i)) => word(s.s, fmt!("%u", i)),
+        ast::vstore_fixed(None) => word(s.s, ~"_"),
+        ast::vstore_uniq => word(s.s, ~"~"),
+        ast::vstore_box => word(s.s, ~"@"),
+        ast::vstore_slice(r) => print_region(s, r, ~"/")
     }
 }
 
@@ -1455,7 +1455,7 @@ fn print_path(s: ps, &&path: @ast::path, colons_before_params: bool) {
           None => { /* ok */ }
           Some(r) => {
             word(s.s, ~"/");
-            print_region(s, r);
+            print_region(s, r, ~"");
           }
         }