about summary refs log tree commit diff
path: root/src/comp
diff options
context:
space:
mode:
authorRafael Ávila de Espíndola <respindola@mozilla.com>2010-12-24 23:25:02 -0500
committerGraydon Hoare <graydon@mozilla.com>2010-12-24 21:06:14 -0800
commitf900792fa344d9518bf34fe416f25a89be555ba1 (patch)
treed7cd59ce16c70000e26e57fd58955700387cc7cf /src/comp
parent8d2fdac93bd4acf41a150404e1f6579ad45b9172 (diff)
downloadrust-f900792fa344d9518bf34fe416f25a89be555ba1.tar.gz
rust-f900792fa344d9518bf34fe416f25a89be555ba1.zip
Parse 'import' directives in rustc.
Diffstat (limited to 'src/comp')
-rw-r--r--src/comp/front/parser.rs44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/comp/front/parser.rs b/src/comp/front/parser.rs
index 074d0a8743e..f302fb1b694 100644
--- a/src/comp/front/parser.rs
+++ b/src/comp/front/parser.rs
@@ -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;
             }