With the attached patch rustc can parse:

------------
use std;
use std();
use std(name = "foo");
use std(name = "foo", bar = "zed");

fn main() {
}
------------

I am setting up a github account and repo, but for now the patch is attached

Questions:

*) Are use and imports allowed anywhere in the file?
*) How do I add a test that uses rustc?
*) Is there a syntax only mode? I had to add the main function to prevent a crash.

Cheers,
Rafael
diff --git a/src/comp/front/parser.rs b/src/comp/front/parser.rs
index a3b0462..0020138 100644
--- a/src/comp/front/parser.rs
+++ b/src/comp/front/parser.rs
@@ -1445,9 +1445,62 @@ 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("foobar");
+        }
+    }
+}
+
+impure fn parse_meta(parser p) {
+    expect(p, token.LPAREN);
+    while (p.peek() != token.RPAREN) {
+        parse_meta_item(p);
+        while (p.peek() == token.COMMA) {
+            p.bump();
+            parse_meta_item(p);
+        }
+    }
+    expect(p, token.RPAREN);
+}
+
+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;
+    parse_use_and_imports(p);
     auto m = parse_mod_items(p, token.EOF);
     ret @spanned(lo, hi, rec(module=m));
 }
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to