Skip to content

import globbing now works #425

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/comp/front/ast.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import std::map::hashmap;
import std::option;
import std::str;
import std::vec;
Expand Down Expand Up @@ -401,6 +400,7 @@ type view_item = spanned[view_item_];
tag view_item_ {
view_item_use(ident, vec[@meta_item], def_id, ann);
view_item_import(ident, vec[ident], def_id);
view_item_import_glob(vec[ident], def_id);
view_item_export(ident);
}

Expand Down
53 changes: 41 additions & 12 deletions src/comp/front/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2183,29 +2183,58 @@ fn parse_use(&parser p) -> @ast::view_item {
}

fn parse_rest_import_name(&parser p, ast::ident first,
option::t[ast::ident] def_ident)
option::t[ast::ident] def_ident)
-> @ast::view_item {
auto lo = p.get_lo_pos();
let vec[ast::ident] identifiers = [first];
while (p.peek() != token::SEMI) {
expect(p, token::MOD_SEP);
auto i = parse_ident(p);
identifiers += [i];
let bool glob = false;

while (true) {
alt (p.peek()) {
case (token::SEMI) {
p.bump();
break;
}
case (token::MOD_SEP) {
if (glob) { p.err("cannot path into a glob"); }
p.bump();
}
case (_) { p.err("expecting '::' or ';'"); }
}
alt (p.peek()) {
case (token::IDENT(_,_)) {
identifiers += [parse_ident(p)];
}
//the lexer can't tell the different kinds of stars apart ) :
case (token::BINOP(token::STAR)) {
glob = true;
p.bump();
}
case (_) { p.err("expecting an identifier, or '*'"); }
}
}
auto hi = p.get_hi_pos();
p.bump();
auto defined_id;
auto import_decl;
alt (def_ident) {
case(some[ast::ident](?i)) {
defined_id = i;
if (glob) {
p.err("globbed imports can't be renamed");
}
import_decl = ast::view_item_import(i, identifiers,
p.next_def_id());
}
case (_) {
auto len = vec::len[ast::ident](identifiers);
defined_id = identifiers.(len - 1u);
if (glob) {
import_decl = ast::view_item_import_glob(identifiers,
p.next_def_id());
} else {
auto len = vec::len[ast::ident](identifiers);
import_decl = ast::view_item_import(identifiers.(len - 1u),
identifiers,
p.next_def_id());
}
}
}
auto import_decl = ast::view_item_import(defined_id, identifiers,
p.next_def_id());
ret @spanned(lo, hi, import_decl);
}

Expand Down
Loading