about summary refs log tree commit diff
path: root/src/comp/syntax/parse/eval.rs
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/eval.rs
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/eval.rs')
-rw-r--r--src/comp/syntax/parse/eval.rs20
1 files changed, 14 insertions, 6 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