about summary refs log tree commit diff
path: root/src/comp/front
diff options
context:
space:
mode:
authorRafael Ávila de Espíndola <respindola@mozilla.com>2010-12-24 17:03:46 -0800
committerGraydon Hoare <graydon@mozilla.com>2010-12-24 17:03:46 -0800
commit8d2fdac93bd4acf41a150404e1f6579ad45b9172 (patch)
treee7219c3b151f33ce0efd563f978b505e5a3ecf61 /src/comp/front
parentd9482089789afbe0b5ad929f77ea3480fb9fcd62 (diff)
downloadrust-8d2fdac93bd4acf41a150404e1f6579ad45b9172.tar.gz
rust-8d2fdac93bd4acf41a150404e1f6579ad45b9172.zip
Parse 'use' directives in rustc.
Diffstat (limited to 'src/comp/front')
-rw-r--r--src/comp/front/parser.rs47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/comp/front/parser.rs b/src/comp/front/parser.rs
index cd4ef3e171b..074d0a8743e 100644
--- a/src/comp/front/parser.rs
+++ b/src/comp/front/parser.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;