@@ -203,6 +203,7 @@ fn Parser(sess: parse_sess, cfg: ast::crate_cfg,
203203 strict_keywords: token:: strict_keyword_table( ) ,
204204 reserved_keywords: token:: reserved_keyword_table( ) ,
205205 obsolete_set: std:: map:: HashMap ( ) ,
206+ mod_path_stack: ~[ ] ,
206207 }
207208}
208209
@@ -226,6 +227,8 @@ struct Parser {
226227 /// The set of seen errors about obsolete syntax. Used to suppress
227228 /// extra detail when the same error is seen twice
228229 obsolete_set: HashMap <ObsoleteSyntax , ( ) >,
230+ /// Used to determine the path to externally loaded source files
231+ mut mod_path_stack: ~[ ~str ] ,
229232
230233 drop { } /* do not copy the parser; its state is tied to outside state */
231234}
@@ -3041,10 +3044,12 @@ impl Parser {
30413044 let (m, attrs) = self.eval_src_mod(id, outer_attrs, id_span);
30423045 (id, m, Some(move attrs))
30433046 } else {
3047+ self.push_mod_path(id, outer_attrs);
30443048 self.expect(token::LBRACE);
30453049 let inner_attrs = self.parse_inner_attrs_and_next();
30463050 let m = self.parse_mod_items(token::RBRACE, inner_attrs.next);
30473051 self.expect(token::RBRACE);
3052+ self.pop_mod_path();
30483053 (id, item_mod(m), Some(inner_attrs.inner))
30493054 };
30503055
@@ -3081,20 +3086,40 @@ impl Parser {
30813086 }
30823087 }
30833088
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+
30843104 fn eval_src_mod(id: ast::ident,
30853105 outer_attrs: ~[ast::attribute],
30863106 id_sp: span) -> (ast::item_, ~[ast::attribute]) {
3107+
30873108 let prefix = Path(self.sess.cm.span_to_filename(copy self.span));
30883109 let prefix = prefix.dir_path();
3110+ let mod_path = Path(" . ").push_many(self.mod_path_stack);
30893111 let default_path = self.sess.interner.get(id) + ~" . rs";
30903112 let file_path = match ::attr::first_attr_value_str_by_name(
3091- outer_attrs, ~" path ") {
3113+ outer_attrs, ~" path2 ") {
30923114
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+ }
30953121 };
30963122
3097- let file_path = Path(file_path);
30983123 self.eval_src_mod_from_path(prefix, file_path,
30993124 outer_attrs, id_sp)
31003125 }
0 commit comments