Parse 'use' directives in rustc.
This commit is contained in:
parent
d948208978
commit
8d2fdac93b
@ -559,6 +559,7 @@ TEST_XFAILS_SELF := $(filter-out \
|
||||
u8-incr-decr.rs \
|
||||
uint.rs \
|
||||
unit.rs \
|
||||
use.rs \
|
||||
tag.rs \
|
||||
vec.rs \
|
||||
vec-drop.rs \
|
||||
|
@ -1330,6 +1330,8 @@ impure fn parse_item_obj(parser p, ast.layer lyr) -> @ast.item {
|
||||
}
|
||||
|
||||
impure fn parse_mod_items(parser p, token.token term) -> ast._mod {
|
||||
parse_use_and_imports(p);
|
||||
|
||||
let vec[@ast.item] items = vec();
|
||||
auto index = new_str_hash[ast.mod_index_entry]();
|
||||
let uint u = 0u;
|
||||
@ -1531,6 +1533,51 @@ impure fn parse_item(parser p) -> @ast.item {
|
||||
fail;
|
||||
}
|
||||
|
||||
impure fn parse_meta_item(parser p) {
|
||||
auto ident = parse_ident(p);
|
||||
expect(p, token.EQ);
|
||||
alt (p.peek()) {
|
||||
case (token.LIT_STR(?s)) {
|
||||
p.bump();
|
||||
}
|
||||
case (_) {
|
||||
p.err("Metadata items must be string literals");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impure fn parse_meta(parser p) {
|
||||
auto pf = parse_meta_item;
|
||||
parse_seq[()](token.LPAREN, token.RPAREN, some(token.COMMA), pf, p);
|
||||
}
|
||||
|
||||
impure fn parse_optional_meta(parser p) {
|
||||
alt (p.peek()) {
|
||||
case (token.LPAREN) {
|
||||
ret parse_meta(p);
|
||||
}
|
||||
case (_) {
|
||||
ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impure fn parse_use_and_imports(parser p) {
|
||||
while (true) {
|
||||
alt (p.peek()) {
|
||||
case (token.USE) {
|
||||
p.bump();
|
||||
auto ident = parse_ident(p);
|
||||
parse_optional_meta(p);
|
||||
expect(p, token.SEMI);
|
||||
}
|
||||
case (_) {
|
||||
ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impure fn parse_crate(parser p) -> @ast.crate {
|
||||
auto lo = p.get_span();
|
||||
auto hi = lo;
|
||||
|
14
src/test/run-pass/use.rs
Normal file
14
src/test/run-pass/use.rs
Normal file
@ -0,0 +1,14 @@
|
||||
use std;
|
||||
use libc();
|
||||
use zed(name = "std");
|
||||
use bar(name = "std", ver = "0.0.1");
|
||||
|
||||
mod baz {
|
||||
use std;
|
||||
use libc();
|
||||
use zed(name = "std");
|
||||
use bar(name = "std", ver = "0.0.1");
|
||||
}
|
||||
|
||||
fn main() {
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user