From 67cc5b9e346cba9cc8fdaa00e38ef26b4d9936cf Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Tue, 16 Aug 2011 12:09:47 -0700 Subject: [PATCH] Allow multiple exports in a single export statement. Issue #817 --- src/comp/syntax/ast.rs | 14 +++++++------- src/comp/syntax/parse/parser.rs | 5 +++-- src/comp/syntax/print/pprust.rs | 6 +++++- src/test/run-pass/export-multi.rs | 16 ++++++++++++++++ 4 files changed, 31 insertions(+), 10 deletions(-) create mode 100644 src/test/run-pass/export-multi.rs diff --git a/src/comp/syntax/ast.rs b/src/comp/syntax/ast.rs index 9fedd515620..ec63af65729 100644 --- a/src/comp/syntax/ast.rs +++ b/src/comp/syntax/ast.rs @@ -564,7 +564,7 @@ tag view_item_ { view_item_use(ident, [@meta_item], node_id); view_item_import(ident, [ident], node_id); view_item_import_glob([ident], node_id); - view_item_export(ident, node_id); + view_item_export([ident], node_id); } type obj_def_ids = {ty: node_id, ctor: node_id}; @@ -627,11 +627,11 @@ fn is_exported(i: ident, m: _mod) -> bool { let count = 0u; for vi: @ast::view_item in m.view_items { alt vi.node { - ast::view_item_export(id, _) { - if str::eq(i, id) { - // even if it's nonlocal (since it's explicit) - - ret true; + ast::view_item_export(ids, _) { + for id in ids { + if str::eq(i, id) { + ret true; + } } count += 1u; } @@ -640,7 +640,7 @@ fn is_exported(i: ident, m: _mod) -> bool { } // If there are no declared exports then // everything not imported is exported - + // even if it's nonlocal (since it's explicit) ret count == 0u && !nonlocal; } diff --git a/src/comp/syntax/parse/parser.rs b/src/comp/syntax/parse/parser.rs index 267308c1c04..e6b65444029 100644 --- a/src/comp/syntax/parse/parser.rs +++ b/src/comp/syntax/parse/parser.rs @@ -2353,8 +2353,9 @@ fn parse_import(p: &parser) -> ast::view_item_ { } fn parse_export(p: &parser) -> ast::view_item_ { - let id = parse_ident(p); - ret ast::view_item_export(id, p.get_id()); + let ids = parse_seq_to_before_end( + token::SEMI, option::some(token::COMMA), parse_ident, p); + ret ast::view_item_export(ids, p.get_id()); } fn parse_view_item(p: &parser) -> @ast::view_item { diff --git a/src/comp/syntax/print/pprust.rs b/src/comp/syntax/print/pprust.rs index 7bd89ed36d9..43ab6c5c823 100644 --- a/src/comp/syntax/print/pprust.rs +++ b/src/comp/syntax/print/pprust.rs @@ -1276,7 +1276,11 @@ fn print_view_item(s: &ps, item: &@ast::view_item) { } word(s.s, "::*"); } - ast::view_item_export(id, _) { head(s, "export"); word(s.s, id); } + ast::view_item_export(ids, _) { + head(s, "export"); + commasep(s, inconsistent, ids, + fn(s: &ps, w: &str) { word(s.s, w) }); + } } word(s.s, ";"); end(s); // end inner head-block diff --git a/src/test/run-pass/export-multi.rs b/src/test/run-pass/export-multi.rs new file mode 100644 index 00000000000..9f382cb4b77 --- /dev/null +++ b/src/test/run-pass/export-multi.rs @@ -0,0 +1,16 @@ +import m::f; +import m::g; + +mod m { + export f, g; + + fn f() {} + fn g() {} +} + +fn main() { + f(); + g(); + m::f(); + m::g(); +} \ No newline at end of file