mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
Parse 'import' directives in rustc.
This commit is contained in:
parent
8d2fdac93b
commit
f900792fa3
@ -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()) {
|
||||
@ -1571,6 +1610,11 @@ impure fn parse_use_and_imports(parser p) {
|
||||
parse_optional_meta(p);
|
||||
expect(p, token.SEMI);
|
||||
}
|
||||
case (token.IMPORT) {
|
||||
p.bump();
|
||||
parse_import(p);
|
||||
expect(p, token.SEMI);
|
||||
}
|
||||
case (_) {
|
||||
ret;
|
||||
}
|
||||
|
@ -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() {
|
||||
|
Loading…
Reference in New Issue
Block a user