On 10-12-22 2:54 PM, Graydon Hoare wrote:
Great. Some comments on the patch:
Thanks for complete review and explanation!
The attached patch should contain all your suggestions and a test.
Should I also add negative tests to check that uses are rejected in
other contexts?
-Graydon
Cheers,
Rafael
diff --git a/src/Makefile b/src/Makefile
index c2d4451..c0eefe3 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -556,6 +556,7 @@ TEST_XFAILS_SELF := $(filter-out \
u8-incr-decr.rs \
uint.rs \
unit.rs \
+ use.rs \
vec.rs \
vec-drop.rs \
vec-in-tup.rs \
diff --git a/src/comp/front/parser.rs b/src/comp/front/parser.rs
index a3b0462..2b114cf 100644
--- a/src/comp/front/parser.rs
+++ b/src/comp/front/parser.rs
@@ -1250,6 +1250,8 @@ impure fn parse_item_fn(parser p, ast.effect eff) ->
@ast.item {
}
impure fn parse_mod_items(parser p, token.token term) -> ast._mod {
+ parse_use_and_imports(p);
+
let [email protected]] items = vec();
auto index = new_str_hash[ast.mod_index_entry]();
let uint u = 0u;
@@ -1445,6 +1447,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;
diff --git a/src/test/run-pass/use.rs b/src/test/run-pass/use.rs
new file mode 100644
index 0000000..ab3e5e4
--- /dev/null
+++ b/src/test/run-pass/use.rs
@@ -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() {
+}
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev