about summary refs log tree commit diff
path: root/src/comp/syntax/parse/parser.rs
diff options
context:
space:
mode:
authorTim Chevalier <chevalier@alum.wellesley.edu>2012-01-22 21:09:43 -0800
committerTim Chevalier <chevalier@alum.wellesley.edu>2012-01-23 15:48:08 -0800
commit9dc59e15061827122dc0f08d3f66acd17ba329dc (patch)
treed98b61d751f5db6d33c844d3706a9c6a4f399524 /src/comp/syntax/parse/parser.rs
parente51599932478db1d841912a6e0a10cbc20335e1f (diff)
downloadrust-9dc59e15061827122dc0f08d3f66acd17ba329dc.tar.gz
rust-9dc59e15061827122dc0f08d3f66acd17ba329dc.zip
Export all enum variants by default; new syntax for selectively exporting variants
See issue 1426 for details. Now, the semantics of "export t;" where t is a tag are
to export all of t's variants as well. "export t{};" exports t but not its
variants, while "export t{a, b, c};" exports only variants a, b, c of t.

To do:
- documentation
- there's currently no checking that a, b, c are actually variants of t in the
 above example
- there's also no checking that t is an enum type, in the second two examples above
- change the modules listed in issue 1426 that should have the old export
semantics to use the t{} syntax

I deleted the test export-no-tag-variants since we're doing the opposite now,
and other tests cover the same behavior.
Diffstat (limited to 'src/comp/syntax/parse/parser.rs')
-rw-r--r--src/comp/syntax/parse/parser.rs23
1 files changed, 12 insertions, 11 deletions
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 {