diff options
| author | Patrick Walton <pcwalton@mimiga.net> | 2012-08-31 11:19:07 -0700 |
|---|---|---|
| committer | Patrick Walton <pcwalton@mimiga.net> | 2012-08-31 11:20:50 -0700 |
| commit | 6e7d5e1cbddeee95a1a7c996b99d78dec0da2954 (patch) | |
| tree | 1adc1f94f8f3888132261b4e26055586fac30d8f /src/libsyntax | |
| parent | 28b1473f8472099260d2b76422e7df49de0e01a1 (diff) | |
| download | rust-6e7d5e1cbddeee95a1a7c996b99d78dec0da2954.tar.gz rust-6e7d5e1cbddeee95a1a7c996b99d78dec0da2954.zip | |
rustc: Implement "use mod"
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ast.rs | 18 | ||||
| -rw-r--r-- | src/libsyntax/ast_map.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/ast_util.rs | 6 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 50 | ||||
| -rw-r--r-- | src/libsyntax/print/pprust.rs | 15 |
5 files changed, 54 insertions, 37 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index efb1116bf44..693fc4df5d0 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -1110,6 +1110,15 @@ type path_list_ident_ = {name: ident, id: node_id}; type path_list_ident = spanned<path_list_ident_>; #[auto_serialize] +enum namespace { module_ns, type_value_ns } + +impl namespace : cmp::Eq { + pure fn eq(&&other: namespace) -> bool { + (self as uint) == (other as uint) + } +} + +#[auto_serialize] type view_path = spanned<view_path_>; #[auto_serialize] @@ -1120,7 +1129,7 @@ enum view_path_ { // or just // // foo::bar::baz (with 'baz =' implicitly on the left) - view_path_simple(ident, @path, node_id), + view_path_simple(ident, @path, namespace, node_id), // foo::bar::* view_path_glob(@path, node_id), @@ -1152,12 +1161,7 @@ enum attr_style { attr_outer, attr_inner, } impl attr_style : cmp::Eq { pure fn eq(&&other: attr_style) -> bool { - match (self, other) { - (attr_outer, attr_outer) => true, - (attr_inner, attr_inner) => true, - (attr_outer, _) => false, - (attr_inner, _) => false, - } + (self as uint) == (other as uint) } } diff --git a/src/libsyntax/ast_map.rs b/src/libsyntax/ast_map.rs index 4f90335a2c3..e377707ece7 100644 --- a/src/libsyntax/ast_map.rs +++ b/src/libsyntax/ast_map.rs @@ -293,7 +293,7 @@ fn map_view_item(vi: @view_item, cx: ctx, _v: vt) { match vi.node { view_item_export(vps) => for vps.each |vp| { let (id, name) = match vp.node { - view_path_simple(nm, _, id) => { + view_path_simple(nm, _, _, id) => { (id, /* FIXME (#2543) */ copy nm) } view_path_glob(pth, id) | view_path_list(pth, _, id) => { diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index 8e9ca7bd098..3badb0fbfce 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -211,7 +211,7 @@ fn is_exported(i: ident, m: _mod) -> bool { has_explicit_exports = true; for vps.each |vp| { match vp.node { - ast::view_path_simple(id, _, _) => { + ast::view_path_simple(id, _, _, _) => { if id == i { return true; } match parent_enum { Some(parent_enum_id) => { @@ -442,7 +442,7 @@ fn id_visitor(vfn: fn@(node_id)) -> visit::vt<()> { view_item_import(vps) | view_item_export(vps) => { do vec::iter(vps) |vp| { match vp.node { - view_path_simple(_, _, id) => vfn(id), + view_path_simple(_, _, _, id) => vfn(id), view_path_glob(_, id) => vfn(id), view_path_list(_, _, id) => vfn(id) } @@ -602,7 +602,7 @@ fn walk_pat(pat: @pat, it: fn(@pat)) { fn view_path_id(p: @view_path) -> node_id { match p.node { - view_path_simple(_, _, id) | view_path_glob(_, id) | + view_path_simple(_, _, _, id) | view_path_glob(_, id) | view_path_list(_, _, id) => id } } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index c83e6893e3c..03bb41698cc 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -40,24 +40,25 @@ import ast::{_mod, add, alt_check, alt_exhaustive, arg, arm, attribute, lit_int_unsuffixed, lit_nil, lit_str, lit_uint, local, m_const, m_imm, m_mutbl, mac_, mac_aq, mac_ellipsis, mac_invoc, mac_invoc_tt, mac_var, matcher, match_nonterminal, match_seq, - match_tok, method, mode, mt, mul, mutability, named_field, neg, - noreturn, not, pat, pat_box, pat_enum, pat_ident, pat_lit, - pat_range, pat_rec, 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, 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, sty_value, token_tree, trait_method, - trait_ref, tt_delim, tt_seq, tt_tok, tt_nonterminal, ty, ty_, - ty_bot, ty_box, ty_field, ty_fn, ty_infer, ty_mac, ty_method, - ty_nil, ty_param, ty_param_bound, ty_path, ty_ptr, ty_rec, - ty_rptr, ty_tup, ty_u32, ty_uniq, ty_vec, ty_fixed_length, - tuple_variant_kind, unchecked_blk, uniq, unnamed_field, - unsafe_blk, unsafe_fn, variant, view_item, view_item_, - view_item_export, view_item_import, view_item_use, view_path, - view_path_glob, view_path_list, view_path_simple, visibility, - vstore, vstore_box, vstore_fixed, vstore_slice, vstore_uniq}; + match_tok, method, mode, module_ns, mt, mul, mutability, + named_field, neg, noreturn, not, pat, pat_box, pat_enum, + pat_ident, pat_lit, pat_range, pat_rec, 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, + 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, + sty_value, token_tree, trait_method, trait_ref, tt_delim, tt_seq, + tt_tok, tt_nonterminal, tuple_variant_kind, ty, ty_, ty_bot, + ty_box, ty_field, ty_fn, ty_infer, ty_mac, ty_method, ty_nil, + ty_param, ty_param_bound, ty_path, ty_ptr, ty_rec, ty_rptr, + ty_tup, ty_u32, ty_uniq, ty_vec, ty_fixed_length, type_value_ns, + unchecked_blk, uniq, unnamed_field, unsafe_blk, unsafe_fn, + variant, view_item, view_item_, view_item_export, + view_item_import, view_item_use, view_path, view_path_glob, + view_path_list, view_path_simple, visibility, vstore, vstore_box, + vstore_fixed, vstore_slice, vstore_uniq}; export file_type; export parser; @@ -3336,6 +3337,14 @@ struct parser { fn parse_view_path() -> @view_path { let lo = self.span.lo; + + let namespace; + if self.eat_keyword(~"mod") { + namespace = module_ns; + } else { + namespace = type_value_ns; + } + let first_ident = self.parse_ident(); let mut path = ~[first_ident]; debug!("parsed view_path: %s", *self.id_to_str(first_ident)); @@ -3352,7 +3361,8 @@ struct parser { let path = @{span: mk_sp(lo, self.span.hi), global: false, idents: path, rp: None, types: ~[]}; return @spanned(lo, self.span.hi, - view_path_simple(first_ident, path, self.get_id())); + view_path_simple(first_ident, path, namespace, + self.get_id())); } token::MOD_SEP => { @@ -3400,7 +3410,7 @@ struct parser { let path = @{span: mk_sp(lo, self.span.hi), global: false, idents: path, rp: None, types: ~[]}; return @spanned(lo, self.span.hi, - view_path_simple(last, path, self.get_id())); + view_path_simple(last, path, namespace, self.get_id())); } fn parse_view_paths() -> ~[@view_path] { diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index fcc95865e4d..8f27fa4f47b 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -468,11 +468,11 @@ fn print_item(s: ps, &&item: @ast::item) { ast::item_foreign_mod(nmod) => { head(s, ~"extern"); match nmod.sort { - ast::named => { - word_nbsp(s, ~"mod"); - print_ident(s, item.ident) - } - ast::anonymous => {} + ast::named => { + word_nbsp(s, ~"mod"); + print_ident(s, item.ident); + } + ast::anonymous => {} } nbsp(s); bopen(s); @@ -1687,7 +1687,10 @@ fn print_meta_item(s: ps, &&item: @ast::meta_item) { fn print_view_path(s: ps, &&vp: @ast::view_path) { match vp.node { - ast::view_path_simple(ident, path, _) => { + ast::view_path_simple(ident, path, namespace, _) => { + if namespace == ast::module_ns { + word_space(s, ~"mod"); + } if path.idents[vec::len(path.idents)-1u] != ident { print_ident(s, ident); space(s.s); |
