From ba5cc236f7596148ad560b0bb651d82d15f0fc7f Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Fri, 20 Jan 2012 19:44:38 -0800 Subject: WIP on issue 1426 (exporting all tags) Support Lenny222's proposed syntax for exporting a tag without its variants, or selected tags from a variant, in the AST and parser. No support further down the line yet. Tests are xfailed. --- src/comp/syntax/ast.rs | 4 ++++ src/comp/syntax/parse/parser.rs | 32 ++++++++++++++++++++++++++++---- 2 files changed, 32 insertions(+), 4 deletions(-) (limited to 'src/comp') diff --git a/src/comp/syntax/ast.rs b/src/comp/syntax/ast.rs index 0f7ba99301f..cafea5ed976 100644 --- a/src/comp/syntax/ast.rs +++ b/src/comp/syntax/ast.rs @@ -439,6 +439,10 @@ enum view_item_ { view_item_import_glob(@simple_path, node_id), view_item_import_from(@simple_path, [import_ident], node_id), view_item_export([ident], node_id), + // export foo::{} + view_item_export_tag_none(ident, node_id), + // export foo::{bar, baz, blat} + view_item_export_tag_some(ident, [ident], node_id) } // Meta-data associated with an item diff --git a/src/comp/syntax/parse/parser.rs b/src/comp/syntax/parse/parser.rs index 46b6c474363..d020c46c6a0 100644 --- a/src/comp/syntax/parse/parser.rs +++ b/src/comp/syntax/parse/parser.rs @@ -2391,11 +2391,35 @@ fn parse_import(p: parser) -> ast::view_item_ { } } +fn parse_tag_export(p:parser, tyname:ast::ident) -> ast::view_item_ { + let tagnames:[ast::ident] = + parse_seq(token::LBRACE, token::RBRACE, + seq_sep(token::COMMA), {|p| parse_ident(p) }, p).node; + let id = p.get_id(); + if vec::is_empty(tagnames) { + ret ast::view_item_export_tag_none(tyname, id); + } + else { + ret ast::view_item_export_tag_some(tyname, tagnames, id); + } +} + fn parse_export(p: parser) -> ast::view_item_ { - let ids = - parse_seq_to_before_end(token::SEMI, seq_sep(token::COMMA), - parse_ident, p); - ret ast::view_item_export(ids, p.get_id()); + let first = parse_ident(p); + alt p.token { + token::COLON { + p.bump(); + expect(p, token::COLON); + ret parse_tag_export(p, first); + } + t { + if t == token::COMMA { p.bump(); } + let ids = + parse_seq_to_before_end(token::SEMI, seq_sep(token::COMMA), + parse_ident, p); + ret ast::view_item_export(vec::concat([[first], ids]), p.get_id()); + } + } } fn parse_view_item(p: parser) -> @ast::view_item { -- cgit 1.4.1-3-g733a5