Add filename to Parser

This commit is contained in:
Jeffrey Seyfried 2016-03-02 01:40:15 +00:00
parent b9e61c9f40
commit cccc0880d9

View File

@ -273,6 +273,7 @@ pub struct Parser<'a> {
/// extra detail when the same error is seen twice /// extra detail when the same error is seen twice
pub obsolete_set: HashSet<ObsoleteSyntax>, pub obsolete_set: HashSet<ObsoleteSyntax>,
/// Used to determine the path to externally loaded source files /// Used to determine the path to externally loaded source files
pub filename: Option<String>,
pub mod_path_stack: Vec<InternedString>, pub mod_path_stack: Vec<InternedString>,
/// Stack of spans of open delimiters. Used for error message. /// Stack of spans of open delimiters. Used for error message.
pub open_braces: Vec<Span>, pub open_braces: Vec<Span>,
@ -354,6 +355,9 @@ impl<'a> Parser<'a> {
{ {
let tok0 = rdr.real_token(); let tok0 = rdr.real_token();
let span = tok0.sp; let span = tok0.sp;
let filename = if span != codemap::DUMMY_SP {
Some(sess.codemap().span_to_filename(span))
} else { None };
let placeholder = TokenAndSpan { let placeholder = TokenAndSpan {
tok: token::Underscore, tok: token::Underscore,
sp: span, sp: span,
@ -382,6 +386,7 @@ impl<'a> Parser<'a> {
quote_depth: 0, quote_depth: 0,
obsolete_set: HashSet::new(), obsolete_set: HashSet::new(),
mod_path_stack: Vec::new(), mod_path_stack: Vec::new(),
filename: filename,
open_braces: Vec::new(), open_braces: Vec::new(),
owns_directory: true, owns_directory: true,
root_module_name: None, root_module_name: None,
@ -5325,7 +5330,7 @@ impl<'a> Parser<'a> {
id: ast::Ident, id: ast::Ident,
outer_attrs: &[ast::Attribute], outer_attrs: &[ast::Attribute],
id_sp: Span) -> PResult<'a, ModulePathSuccess> { id_sp: Span) -> PResult<'a, ModulePathSuccess> {
let mut prefix = PathBuf::from(&self.sess.codemap().span_to_filename(self.span)); let mut prefix = PathBuf::from(self.filename.as_ref().unwrap());
prefix.pop(); prefix.pop();
let mut dir_path = prefix; let mut dir_path = prefix;
for part in &self.mod_path_stack { for part in &self.mod_path_stack {