Skip to content
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

Import #186

Closed
wants to merge 1 commit 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
43 changes: 43 additions & 0 deletions src/comp/front/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1562,6 +1562,45 @@ impure fn parse_optional_meta(parser p) {
}
}

impure fn parse_rest_import_name(parser p, ast.ident id) {
while (p.peek() != token.SEMI) {
expect(p, token.DOT);
parse_ident(p);
}
}

impure fn parse_full_import_name(parser p) {
alt (p.peek()) {
case (token.IDENT(?ident)) {
p.bump();
parse_rest_import_name(p, ident);
}
case (_) {
p.err("expecting an identifier");
}
}
}

impure fn parse_import(parser p) {
alt (p.peek()) {
case (token.IDENT(?ident)) {
p.bump();
alt (p.peek()) {
case (token.EQ) {
p.bump();
parse_full_import_name(p);
}
case (_) {
parse_rest_import_name(p, ident);
}
}
}
case (_) {
p.err("expecting an identifier");
}
}
}

impure fn parse_use_and_imports(parser p) {
while (true) {
alt (p.peek()) {
Expand All @@ -1570,6 +1609,10 @@ impure fn parse_use_and_imports(parser p) {
auto ident = parse_ident(p);
parse_optional_meta(p);
expect(p, token.SEMI);
} case (token.IMPORT) {
p.bump();
parse_import(p);
expect(p, token.SEMI);
}
case (_) {
ret;
Expand Down
7 changes: 7 additions & 0 deletions src/test/run-pass/use.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,18 @@ use libc();
use zed(name = "std");
use bar(name = "std", ver = "0.0.1");

import std._str;
import x = std._str;


mod baz {
use std;
use libc();
use zed(name = "std");
use bar(name = "std", ver = "0.0.1");

import std._str;
import x = std._str;
}

fn main() {
Expand Down