diff options
| author | Rafael Ávila de Espíndola <[email protected]> | 2011-01-28 11:54:59 -0500 |
|---|---|---|
| committer | Rafael Ávila de Espíndola <[email protected]> | 2011-01-28 11:54:59 -0500 |
| commit | 3cac20dae3272728282466467cb0193d7dbbf00c (patch) | |
| tree | a257f43c91b257ce34eb8eff0d4839af8787075f /src/comp/front | |
| parent | Add helper function for derived type descriptors. (diff) | |
| download | rust-3cac20dae3272728282466467cb0193d7dbbf00c.tar.xz rust-3cac20dae3272728282466467cb0193d7dbbf00c.zip | |
Correctly handle "import foo = bar.zed;".
Diffstat (limited to 'src/comp/front')
| -rw-r--r-- | src/comp/front/ast.rs | 8 | ||||
| -rw-r--r-- | src/comp/front/parser.rs | 28 |
2 files changed, 24 insertions, 12 deletions
diff --git a/src/comp/front/ast.rs b/src/comp/front/ast.rs index 2ae4c907..70da87dd 100644 --- a/src/comp/front/ast.rs +++ b/src/comp/front/ast.rs @@ -231,7 +231,7 @@ type variant = rec(str name, vec[variant_arg] args, def_id id, ann ann); type view_item = spanned[view_item_]; tag view_item_ { view_item_use(ident, vec[@meta_item], def_id); - view_item_import(vec[ident], def_id, option.t[def]); + view_item_import(ident, vec[ident], def_id, option.t[def]); } type item = spanned[item_]; @@ -249,10 +249,8 @@ fn index_view_item(mod_index index, @view_item it) { case(ast.view_item_use(?id, _, _)) { index.insert(id, ast.mie_view_item(it)); } - case(ast.view_item_import(?ids,_,_)) { - auto len = _vec.len[ast.ident](ids); - auto last_id = ids.(len - 1u); - index.insert(last_id, ast.mie_view_item(it)); + case(ast.view_item_import(?def_ident,_,_,_)) { + index.insert(def_ident, ast.mie_view_item(it)); } } } diff --git a/src/comp/front/parser.rs b/src/comp/front/parser.rs index 5444e5fd..5c13ef86 100644 --- a/src/comp/front/parser.rs +++ b/src/comp/front/parser.rs @@ -1756,27 +1756,41 @@ impure fn parse_use(parser p) -> @ast.view_item { ret @spanned(lo, hi, use_decl); } -impure fn parse_rest_import_name(parser p, ast.ident id) -> @ast.view_item { +impure fn parse_rest_import_name(parser p, ast.ident first, + option.t[ast.ident] def_ident) + -> @ast.view_item { auto lo = p.get_span(); auto hi = lo; let vec[ast.ident] identifiers = vec(); - identifiers += id; + identifiers += first; while (p.peek() != token.SEMI) { expect(p, token.DOT); auto i = parse_ident(p); identifiers += i; } p.bump(); - auto import_decl = ast.view_item_import(identifiers, p.next_def_id(), + auto defined_id; + alt (def_ident) { + case(some[ast.ident](?i)) { + defined_id = i; + } + case (_) { + auto len = _vec.len[ast.ident](identifiers); + defined_id = identifiers.(len - 1u); + } + } + auto import_decl = ast.view_item_import(defined_id, identifiers, + p.next_def_id(), none[ast.def]); ret @spanned(lo, hi, import_decl); } -impure fn parse_full_import_name(parser p) -> @ast.view_item { +impure fn parse_full_import_name(parser p, ast.ident def_ident) + -> @ast.view_item { alt (p.peek()) { case (token.IDENT(?ident)) { p.bump(); - ret parse_rest_import_name(p, ident); + ret parse_rest_import_name(p, ident, some(def_ident)); } case (_) { p.err("expecting an identifier"); @@ -1793,10 +1807,10 @@ impure fn parse_import(parser p) -> @ast.view_item { alt (p.peek()) { case (token.EQ) { p.bump(); - ret parse_full_import_name(p); + ret parse_full_import_name(p, ident); } case (_) { - ret parse_rest_import_name(p, ident); + ret parse_rest_import_name(p, ident, none[ast.ident]); } } } |