about summary refs log tree commit diff
path: root/src/comp/syntax/parse
diff options
context:
space:
mode:
authorHaitao Li <lihaitao@gmail.com>2011-11-22 12:31:09 +0800
committerBrian Anderson <banderson@mozilla.com>2011-11-24 15:31:18 -0800
commit3e303af86b5380c7d53a8879d883cd36ad2a69a6 (patch)
tree342981fb73a0039355f343a2210dbedb95e7c970 /src/comp/syntax/parse
parent547ec241bd50e86752e4c39047b417550f655349 (diff)
downloadrust-3e303af86b5380c7d53a8879d883cd36ad2a69a6.tar.gz
rust-3e303af86b5380c7d53a8879d883cd36ad2a69a6.zip
rustc: Add a path attribute for crate directives
The path information was an optional "filename" component of crate
directive AST. It is now replaced by an attribute with metadata named
"path".

With this commit, a directive

  mod foo = "foo.rs";

should be written as:

  #[path = "foo.rs"]
  mod foo;

Closes issue #906.
Diffstat (limited to 'src/comp/syntax/parse')
-rw-r--r--src/comp/syntax/parse/eval.rs20
-rw-r--r--src/comp/syntax/parse/parser.rs11
2 files changed, 16 insertions, 15 deletions
diff --git a/src/comp/syntax/parse/eval.rs b/src/comp/syntax/parse/eval.rs
index 2c1c0155cf0..bc8a51e1f34 100644
--- a/src/comp/syntax/parse/eval.rs
+++ b/src/comp/syntax/parse/eval.rs
@@ -1,4 +1,5 @@
 
+import front::attr;
 import std::{option, result, io, fs};
 import std::option::{some, none};
 import syntax::ast;
@@ -86,13 +87,21 @@ fn parse_companion_mod(cx: ctx, prefix: str, suffix: option::t<str>)
     }
 }
 
+fn cdir_path_opt(id: str, attrs: [ast::attribute]) -> str {
+    alt attr::get_meta_item_value_str_by_name(attrs, "path") {
+      some(d) {
+        ret d;
+      }
+      none. { ret id; }
+    }
+}
+
 fn eval_crate_directive(cx: ctx, cdir: @ast::crate_directive, prefix: str,
                         &view_items: [@ast::view_item],
                         &items: [@ast::item]) {
     alt cdir.node {
-      ast::cdir_src_mod(id, file_opt, attrs) {
-        let file_path = id + ".rs";
-        alt file_opt { some(f) { file_path = f; } none. { } }
+      ast::cdir_src_mod(id, attrs) {
+        let file_path = cdir_path_opt(id + ".rs", attrs);
         let full_path =
             if std::fs::path_is_absolute(file_path) {
                 file_path
@@ -113,9 +122,8 @@ fn eval_crate_directive(cx: ctx, cdir: @ast::crate_directive, prefix: str,
         cx.byte_pos = p0.get_byte_pos();
         items += [i];
       }
-      ast::cdir_dir_mod(id, dir_opt, cdirs, attrs) {
-        let path = id;
-        alt dir_opt { some(d) { path = d; } none. { } }
+      ast::cdir_dir_mod(id, cdirs, attrs) {
+        let path = cdir_path_opt(id, attrs);
         let full_path =
             if std::fs::path_is_absolute(path) {
                 path
diff --git a/src/comp/syntax/parse/parser.rs b/src/comp/syntax/parse/parser.rs
index 4f81a1dfe73..82c477a7d96 100644
--- a/src/comp/syntax/parse/parser.rs
+++ b/src/comp/syntax/parse/parser.rs
@@ -2475,19 +2475,12 @@ fn parse_crate_directive(p: parser, first_outer_attr: [ast::attribute]) ->
     if expect_mod || is_word(p, "mod") {
         expect_word(p, "mod");
         let id = parse_ident(p);
-        let file_opt =
-            alt p.peek() {
-              token::EQ. { p.bump(); some(parse_str(p)) }
-              _ {
-                attr::get_meta_item_value_str_by_name(outer_attrs, "path")
-              }
-            };
         alt p.peek() {
           // mod x = "foo.rs";
           token::SEMI. {
             let hi = p.get_hi_pos();
             p.bump();
-            ret spanned(lo, hi, ast::cdir_src_mod(id, file_opt, outer_attrs));
+            ret spanned(lo, hi, ast::cdir_src_mod(id, outer_attrs));
           }
           // mod x = "foo_dir" { ...directives... }
           token::LBRACE. {
@@ -2500,7 +2493,7 @@ fn parse_crate_directive(p: parser, first_outer_attr: [ast::attribute]) ->
             let hi = p.get_hi_pos();
             expect(p, token::RBRACE);
             ret spanned(lo, hi,
-                        ast::cdir_dir_mod(id, file_opt, cdirs, mod_attrs));
+                        ast::cdir_dir_mod(id, cdirs, mod_attrs));
           }
           t { unexpected(p, t); }
         }