@@ -203,6 +203,7 @@ fn Parser(sess: parse_sess, cfg: ast::crate_cfg,
203
203
strict_keywords: token:: strict_keyword_table( ) ,
204
204
reserved_keywords: token:: reserved_keyword_table( ) ,
205
205
obsolete_set: std:: map:: HashMap ( ) ,
206
+ mod_path_stack: ~[ ] ,
206
207
}
207
208
}
208
209
@@ -226,6 +227,8 @@ struct Parser {
226
227
/// The set of seen errors about obsolete syntax. Used to suppress
227
228
/// extra detail when the same error is seen twice
228
229
obsolete_set: HashMap <ObsoleteSyntax , ( ) >,
230
+ /// Used to determine the path to externally loaded source files
231
+ mut mod_path_stack: ~[ ~str ] ,
229
232
230
233
drop { } /* do not copy the parser; its state is tied to outside state */
231
234
}
@@ -3041,10 +3044,12 @@ impl Parser {
3041
3044
let (m, attrs) = self.eval_src_mod(id, outer_attrs, id_span);
3042
3045
(id, m, Some(move attrs))
3043
3046
} else {
3047
+ self.push_mod_path(id, outer_attrs);
3044
3048
self.expect(token::LBRACE);
3045
3049
let inner_attrs = self.parse_inner_attrs_and_next();
3046
3050
let m = self.parse_mod_items(token::RBRACE, inner_attrs.next);
3047
3051
self.expect(token::RBRACE);
3052
+ self.pop_mod_path();
3048
3053
(id, item_mod(m), Some(inner_attrs.inner))
3049
3054
};
3050
3055
@@ -3081,20 +3086,40 @@ impl Parser {
3081
3086
}
3082
3087
}
3083
3088
3089
+ fn push_mod_path(id: ident, attrs: ~[ast::attribute]) {
3090
+ let default_path = self.sess.interner.get(id);
3091
+ let file_path = match ::attr::first_attr_value_str_by_name(
3092
+ attrs, ~" path2") {
3093
+
3094
+ Some(ref d) => (*d),
3095
+ None => copy *default_path
3096
+ };
3097
+ self.mod_path_stack.push(file_path)
3098
+ }
3099
+
3100
+ fn pop_mod_path() {
3101
+ self.mod_path_stack.pop();
3102
+ }
3103
+
3084
3104
fn eval_src_mod(id: ast::ident,
3085
3105
outer_attrs: ~[ast::attribute],
3086
3106
id_sp: span) -> (ast::item_, ~[ast::attribute]) {
3107
+
3087
3108
let prefix = Path(self.sess.cm.span_to_filename(copy self.span));
3088
3109
let prefix = prefix.dir_path();
3110
+ let mod_path = Path(" . ").push_many(self.mod_path_stack);
3089
3111
let default_path = self.sess.interner.get(id) + ~" . rs";
3090
3112
let file_path = match ::attr::first_attr_value_str_by_name(
3091
- outer_attrs, ~" path ") {
3113
+ outer_attrs, ~" path2 ") {
3092
3114
3093
- Some(ref d) => (*d),
3094
- None => default_path
3115
+ Some(ref d) => mod_path.push(*d),
3116
+ None => match ::attr::first_attr_value_str_by_name(
3117
+ outer_attrs, ~" path") {
3118
+ Some(ref d) => Path(*d),
3119
+ None => mod_path.push(default_path)
3120
+ }
3095
3121
};
3096
3122
3097
- let file_path = Path(file_path);
3098
3123
self.eval_src_mod_from_path(prefix, file_path,
3099
3124
outer_attrs, id_sp)
3100
3125
}
0 commit comments