about summary refs log tree commit diff
path: root/src/comp/syntax
diff options
context:
space:
mode:
Diffstat (limited to 'src/comp/syntax')
-rw-r--r--src/comp/syntax/ast.rs2
-rw-r--r--src/comp/syntax/ast_util.rs27
-rw-r--r--src/comp/syntax/parse/parser.rs23
-rw-r--r--src/comp/syntax/print/pprust.rs13
4 files changed, 51 insertions, 14 deletions
diff --git a/src/comp/syntax/ast.rs b/src/comp/syntax/ast.rs
index cafea5ed976..661bb68309d 100644
--- a/src/comp/syntax/ast.rs
+++ b/src/comp/syntax/ast.rs
@@ -442,7 +442,7 @@ enum view_item_ {
     // export foo::{}
     view_item_export_tag_none(ident, node_id),
     // export foo::{bar, baz, blat}
-    view_item_export_tag_some(ident, [ident], node_id)
+    view_item_export_tag_some(ident, [import_ident], node_id)
 }
 
 // Meta-data associated with an item
diff --git a/src/comp/syntax/ast_util.rs b/src/comp/syntax/ast_util.rs
index 24b9757a4f4..7a88359d26c 100644
--- a/src/comp/syntax/ast_util.rs
+++ b/src/comp/syntax/ast_util.rs
@@ -113,12 +113,16 @@ fn float_ty_to_str(t: float_ty) -> str {
 
 fn is_exported(i: ident, m: _mod) -> bool {
     let nonlocal = true;
+    let parent_tag : option<ident> = none;
     for it: @item in m.items {
         if it.ident == i { nonlocal = false; }
         alt it.node {
           item_tag(variants, _) {
             for v: variant in variants {
-                if v.node.name == i { nonlocal = false; }
+                if v.node.name == i {
+                   nonlocal = false;
+                   parent_tag = some(it.ident);
+                }
             }
           }
           _ { }
@@ -129,9 +133,28 @@ fn is_exported(i: ident, m: _mod) -> bool {
     for vi: @view_item in m.view_items {
         alt vi.node {
           view_item_export(ids, _) {
-            for id in ids { if str::eq(i, id) { ret true; } }
+              // If any of ids is a tag, we want to consider
+              // all the variants to be exported
+            for id in ids {
+                if str::eq(i, id) { ret true; }
+                alt parent_tag {
+                    some(parent_tag_id) {
+                        if str::eq(id, parent_tag_id) { ret true; }
+                    }
+                    _ { }
+                 }
+            }
             count += 1u;
           }
+          view_item_export_tag_none(id, _) {
+              if str::eq(i, id) { ret true; }
+              count += 1u;
+          }
+          view_item_export_tag_some(id, ids, _) {
+              if str::eq(i, id) { ret true; }
+              for id in ids { if str::eq(i, id.node.name) { ret true; } }
+              count += 1u;
+          }
           _ {/* fall through */ }
         }
     }
diff --git a/src/comp/syntax/parse/parser.rs b/src/comp/syntax/parse/parser.rs
index d020c46c6a0..b18db178fcd 100644
--- a/src/comp/syntax/parse/parser.rs
+++ b/src/comp/syntax/parse/parser.rs
@@ -194,10 +194,18 @@ fn spanned<T: copy>(lo: uint, hi: uint, node: T) -> spanned<T> {
 fn parse_ident(p: parser) -> ast::ident {
     alt p.token {
       token::IDENT(i, _) { p.bump(); ret p.get_str(i); }
-      _ { p.fatal("expecting ident"); }
+      _ { p.fatal("expecting ident, found "
+                  + token::to_str(p.reader, p.token)); }
     }
 }
 
+fn parse_import_ident(p: parser) -> ast::import_ident {
+    let lo = p.span.lo;
+    let ident = parse_ident(p);
+    let hi = p.span.hi;
+    ret spanned(lo, hi, {name: ident, id: p.get_id()});
+}
+
 fn parse_value_ident(p: parser) -> ast::ident {
     check_bad_word(p);
     ret parse_ident(p);
@@ -2316,12 +2324,6 @@ fn parse_rest_import_name(p: parser, first: ast::ident,
 
 
           token::LBRACE {
-            fn parse_import_ident(p: parser) -> ast::import_ident {
-                let lo = p.span.lo;
-                let ident = parse_ident(p);
-                let hi = p.span.hi;
-                ret spanned(lo, hi, {name: ident, id: p.get_id()});
-            }
             let from_idents_ =
                 parse_seq(token::LBRACE, token::RBRACE, seq_sep(token::COMMA),
                           parse_import_ident, p).node;
@@ -2392,9 +2394,9 @@ fn parse_import(p: parser) -> ast::view_item_ {
 }
 
 fn parse_tag_export(p:parser, tyname:ast::ident) -> ast::view_item_ {
-    let tagnames:[ast::ident] =
+    let tagnames:[ast::import_ident] =
         parse_seq(token::LBRACE, token::RBRACE,
-                    seq_sep(token::COMMA), {|p| parse_ident(p) }, p).node;
+             seq_sep(token::COMMA), {|p| parse_import_ident(p) }, p).node;
     let id = p.get_id();
     if vec::is_empty(tagnames) {
        ret ast::view_item_export_tag_none(tyname, id);
@@ -2407,9 +2409,8 @@ fn parse_tag_export(p:parser, tyname:ast::ident) -> ast::view_item_ {
 fn parse_export(p: parser) -> ast::view_item_ {
     let first = parse_ident(p);
     alt p.token {
-       token::COLON {
+       token::MOD_SEP {
            p.bump();
-           expect(p, token::COLON);
            ret parse_tag_export(p, first);
        }
        t {
diff --git a/src/comp/syntax/print/pprust.rs b/src/comp/syntax/print/pprust.rs
index a57cf3add14..2ebcaa055a7 100644
--- a/src/comp/syntax/print/pprust.rs
+++ b/src/comp/syntax/print/pprust.rs
@@ -1303,6 +1303,19 @@ fn print_view_item(s: ps, item: @ast::view_item) {
         commasep(s, inconsistent, ids,
                  fn@(s: ps, &&w: ast::ident) { word(s.s, w) });
       }
+      ast::view_item_export_tag_none(id, _) {
+          head(s, "export");
+          word(s.s, id);
+          word(s.s, "::{}");
+      }
+      ast::view_item_export_tag_some(id, ids, _) {
+          head(s, "export");
+          word(s.s, id);
+          word(s.s, "::{");
+          commasep(s, inconsistent, ids, fn@(s:ps, &&w: ast::import_ident) {
+                  word(s.s, w.node.name) });
+          word(s.s, "}");
+      }
     }
     word(s.s, ";");
     end(s); // end inner head-block