Give the StringReader a sess: &ParseSess.

This commit is contained in:
Jeffrey Seyfried 2017-01-17 01:14:53 +00:00
parent f2d1407743
commit 6466f55ebc
9 changed files with 68 additions and 88 deletions

View File

@ -13,6 +13,7 @@ pub use self::AnnNode::*;
use syntax::abi::Abi; use syntax::abi::Abi;
use syntax::ast; use syntax::ast;
use syntax::codemap::{CodeMap, Spanned}; use syntax::codemap::{CodeMap, Spanned};
use syntax::parse::ParseSess;
use syntax::parse::lexer::comments; use syntax::parse::lexer::comments;
use syntax::print::pp::{self, break_offset, word, space, hardbreak}; use syntax::print::pp::{self, break_offset, word, space, hardbreak};
use syntax::print::pp::{Breaks, eof}; use syntax::print::pp::{Breaks, eof};
@ -21,7 +22,6 @@ use syntax::print::pprust::{self as ast_pp, PrintState};
use syntax::ptr::P; use syntax::ptr::P;
use syntax::symbol::keywords; use syntax::symbol::keywords;
use syntax_pos::{self, BytePos}; use syntax_pos::{self, BytePos};
use errors;
use hir; use hir;
use hir::{PatKind, RegionTyParamBound, TraitTyParamBound, TraitBoundModifier}; use hir::{PatKind, RegionTyParamBound, TraitTyParamBound, TraitBoundModifier};
@ -116,7 +116,7 @@ pub const default_columns: usize = 78;
/// it can scan the input text for comments and literals to /// it can scan the input text for comments and literals to
/// copy forward. /// copy forward.
pub fn print_crate<'a>(cm: &'a CodeMap, pub fn print_crate<'a>(cm: &'a CodeMap,
span_diagnostic: &errors::Handler, sess: &ParseSess,
krate: &hir::Crate, krate: &hir::Crate,
filename: String, filename: String,
input: &mut Read, input: &mut Read,
@ -124,8 +124,7 @@ pub fn print_crate<'a>(cm: &'a CodeMap,
ann: &'a PpAnn, ann: &'a PpAnn,
is_expanded: bool) is_expanded: bool)
-> io::Result<()> { -> io::Result<()> {
let mut s = State::new_from_input(cm, span_diagnostic, filename, input, let mut s = State::new_from_input(cm, sess, filename, input, out, ann, is_expanded);
out, ann, is_expanded);
// When printing the AST, we sometimes need to inject `#[no_std]` here. // When printing the AST, we sometimes need to inject `#[no_std]` here.
// Since you can't compile the HIR, it's not necessary. // Since you can't compile the HIR, it's not necessary.
@ -137,16 +136,14 @@ pub fn print_crate<'a>(cm: &'a CodeMap,
impl<'a> State<'a> { impl<'a> State<'a> {
pub fn new_from_input(cm: &'a CodeMap, pub fn new_from_input(cm: &'a CodeMap,
span_diagnostic: &errors::Handler, sess: &ParseSess,
filename: String, filename: String,
input: &mut Read, input: &mut Read,
out: Box<Write + 'a>, out: Box<Write + 'a>,
ann: &'a PpAnn, ann: &'a PpAnn,
is_expanded: bool) is_expanded: bool)
-> State<'a> { -> State<'a> {
let (cmnts, lits) = comments::gather_comments_and_literals(span_diagnostic, let (cmnts, lits) = comments::gather_comments_and_literals(sess, filename, input);
filename,
input);
State::new(cm, State::new(cm,
out, out,

View File

@ -838,7 +838,7 @@ pub fn print_after_parsing(sess: &Session,
debug!("pretty printing source code {:?}", s); debug!("pretty printing source code {:?}", s);
let sess = annotation.sess(); let sess = annotation.sess();
pprust::print_crate(sess.codemap(), pprust::print_crate(sess.codemap(),
sess.diagnostic(), &sess.parse_sess,
krate, krate,
src_name.to_string(), src_name.to_string(),
&mut rdr, &mut rdr,
@ -896,7 +896,7 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
debug!("pretty printing source code {:?}", s); debug!("pretty printing source code {:?}", s);
let sess = annotation.sess(); let sess = annotation.sess();
pprust::print_crate(sess.codemap(), pprust::print_crate(sess.codemap(),
sess.diagnostic(), &sess.parse_sess,
krate, krate,
src_name.to_string(), src_name.to_string(),
&mut rdr, &mut rdr,
@ -920,7 +920,7 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
debug!("pretty printing source code {:?}", s); debug!("pretty printing source code {:?}", s);
let sess = annotation.sess(); let sess = annotation.sess();
pprust_hir::print_crate(sess.codemap(), pprust_hir::print_crate(sess.codemap(),
sess.diagnostic(), &sess.parse_sess,
krate, krate,
src_name.to_string(), src_name.to_string(),
&mut rdr, &mut rdr,
@ -945,7 +945,7 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
let sess = annotation.sess(); let sess = annotation.sess();
let ast_map = annotation.ast_map().expect("--unpretty missing HIR map"); let ast_map = annotation.ast_map().expect("--unpretty missing HIR map");
let mut pp_state = pprust_hir::State::new_from_input(sess.codemap(), let mut pp_state = pprust_hir::State::new_from_input(sess.codemap(),
sess.diagnostic(), &sess.parse_sess,
src_name.to_string(), src_name.to_string(),
&mut rdr, &mut rdr,
box out, box out,

View File

@ -85,8 +85,7 @@ impl<'a> SpanUtils<'a> {
let filemap = self.sess let filemap = self.sess
.codemap() .codemap()
.new_filemap(String::from("<anon-dxr>"), None, self.snippet(span)); .new_filemap(String::from("<anon-dxr>"), None, self.snippet(span));
let s = self.sess; lexer::StringReader::new(&self.sess.parse_sess, filemap)
lexer::StringReader::new(s.diagnostic(), filemap)
} }
fn span_to_tts(&self, span: Span) -> Vec<TokenTree> { fn span_to_tts(&self, span: Span) -> Vec<TokenTree> {

View File

@ -648,7 +648,7 @@ fn string_to_tts(text: String, parse_sess: &ParseSess) -> Vec<TokenTree> {
let filemap = parse_sess.codemap() let filemap = parse_sess.codemap()
.new_filemap(String::from("<macro expansion>"), None, text); .new_filemap(String::from("<macro expansion>"), None, text);
let lexer = lexer::StringReader::new(&parse_sess.span_diagnostic, filemap); let lexer = lexer::StringReader::new(parse_sess, filemap);
let mut parser = Parser::new(parse_sess, Box::new(lexer), None, false); let mut parser = Parser::new(parse_sess, Box::new(lexer), None, false);
panictry!(parser.parse_all_token_trees()) panictry!(parser.parse_all_token_trees())
} }

View File

@ -13,11 +13,10 @@ pub use self::CommentStyle::*;
use ast; use ast;
use codemap::CodeMap; use codemap::CodeMap;
use syntax_pos::{BytePos, CharPos, Pos}; use syntax_pos::{BytePos, CharPos, Pos};
use errors;
use parse::lexer::is_block_doc_comment; use parse::lexer::is_block_doc_comment;
use parse::lexer::{StringReader, TokenAndSpan}; use parse::lexer::{StringReader, TokenAndSpan};
use parse::lexer::{is_pattern_whitespace, Reader}; use parse::lexer::{is_pattern_whitespace, Reader};
use parse::lexer; use parse::{lexer, ParseSess};
use print::pprust; use print::pprust;
use str::char_at; use str::char_at;
@ -346,16 +345,14 @@ pub struct Literal {
// it appears this function is called only from pprust... that's // it appears this function is called only from pprust... that's
// probably not a good thing. // probably not a good thing.
pub fn gather_comments_and_literals(span_diagnostic: &errors::Handler, pub fn gather_comments_and_literals(sess: &ParseSess, path: String, srdr: &mut Read)
path: String,
srdr: &mut Read)
-> (Vec<Comment>, Vec<Literal>) { -> (Vec<Comment>, Vec<Literal>) {
let mut src = Vec::new(); let mut src = Vec::new();
srdr.read_to_end(&mut src).unwrap(); srdr.read_to_end(&mut src).unwrap();
let src = String::from_utf8(src).unwrap(); let src = String::from_utf8(src).unwrap();
let cm = CodeMap::new(); let cm = CodeMap::new();
let filemap = cm.new_filemap(path, None, src); let filemap = cm.new_filemap(path, None, src);
let mut rdr = lexer::StringReader::new_raw(span_diagnostic, filemap); let mut rdr = lexer::StringReader::new_raw(sess, filemap);
let mut comments: Vec<Comment> = Vec::new(); let mut comments: Vec<Comment> = Vec::new();
let mut literals: Vec<Literal> = Vec::new(); let mut literals: Vec<Literal> = Vec::new();

View File

@ -11,9 +11,9 @@
use ast::{self, Ident}; use ast::{self, Ident};
use syntax_pos::{self, BytePos, CharPos, Pos, Span}; use syntax_pos::{self, BytePos, CharPos, Pos, Span};
use codemap::CodeMap; use codemap::CodeMap;
use errors::{FatalError, Handler, DiagnosticBuilder}; use errors::{FatalError, DiagnosticBuilder};
use ext::tt::transcribe::tt_next_token; use ext::tt::transcribe::tt_next_token;
use parse::token; use parse::{token, ParseSess};
use str::char_at; use str::char_at;
use symbol::{Symbol, keywords}; use symbol::{Symbol, keywords};
use std_unicode::property::Pattern_White_Space; use std_unicode::property::Pattern_White_Space;
@ -82,7 +82,7 @@ impl Default for TokenAndSpan {
} }
pub struct StringReader<'a> { pub struct StringReader<'a> {
pub span_diagnostic: &'a Handler, pub sess: &'a ParseSess,
/// The absolute offset within the codemap of the next character to read /// The absolute offset within the codemap of the next character to read
pub next_pos: BytePos, pub next_pos: BytePos,
/// The absolute offset within the codemap of the current character /// The absolute offset within the codemap of the current character
@ -181,27 +181,22 @@ impl<'a> Reader for TtReader<'a> {
impl<'a> StringReader<'a> { impl<'a> StringReader<'a> {
/// For comments.rs, which hackily pokes into next_pos and ch /// For comments.rs, which hackily pokes into next_pos and ch
pub fn new_raw<'b>(span_diagnostic: &'b Handler, pub fn new_raw<'b>(sess: &'a ParseSess, filemap: Rc<syntax_pos::FileMap>) -> Self {
filemap: Rc<syntax_pos::FileMap>) let mut sr = StringReader::new_raw_internal(sess, filemap);
-> StringReader<'b> {
let mut sr = StringReader::new_raw_internal(span_diagnostic, filemap);
sr.bump(); sr.bump();
sr sr
} }
fn new_raw_internal<'b>(span_diagnostic: &'b Handler, fn new_raw_internal(sess: &'a ParseSess, filemap: Rc<syntax_pos::FileMap>) -> Self {
filemap: Rc<syntax_pos::FileMap>)
-> StringReader<'b> {
if filemap.src.is_none() { if filemap.src.is_none() {
span_diagnostic.bug(&format!("Cannot lex filemap \ sess.span_diagnostic.bug(&format!("Cannot lex filemap without source: {}",
without source: {}", filemap.name));
filemap.name)[..]);
} }
let source_text = (*filemap.src.as_ref().unwrap()).clone(); let source_text = (*filemap.src.as_ref().unwrap()).clone();
StringReader { StringReader {
span_diagnostic: span_diagnostic, sess: sess,
next_pos: filemap.start_pos, next_pos: filemap.start_pos,
pos: filemap.start_pos, pos: filemap.start_pos,
col: CharPos(0), col: CharPos(0),
@ -217,10 +212,8 @@ impl<'a> StringReader<'a> {
} }
} }
pub fn new<'b>(span_diagnostic: &'b Handler, pub fn new(sess: &'a ParseSess, filemap: Rc<syntax_pos::FileMap>) -> Self {
filemap: Rc<syntax_pos::FileMap>) let mut sr = StringReader::new_raw(sess, filemap);
-> StringReader<'b> {
let mut sr = StringReader::new_raw(span_diagnostic, filemap);
if let Err(_) = sr.advance_token() { if let Err(_) = sr.advance_token() {
sr.emit_fatal_errors(); sr.emit_fatal_errors();
panic!(FatalError); panic!(FatalError);
@ -234,12 +227,12 @@ impl<'a> StringReader<'a> {
/// Report a fatal lexical error with a given span. /// Report a fatal lexical error with a given span.
pub fn fatal_span(&self, sp: Span, m: &str) -> FatalError { pub fn fatal_span(&self, sp: Span, m: &str) -> FatalError {
self.span_diagnostic.span_fatal(sp, m) self.sess.span_diagnostic.span_fatal(sp, m)
} }
/// Report a lexical error with a given span. /// Report a lexical error with a given span.
pub fn err_span(&self, sp: Span, m: &str) { pub fn err_span(&self, sp: Span, m: &str) {
self.span_diagnostic.span_err(sp, m) self.sess.span_diagnostic.span_err(sp, m)
} }
@ -274,7 +267,7 @@ impl<'a> StringReader<'a> {
for c in c.escape_default() { for c in c.escape_default() {
m.push(c) m.push(c)
} }
self.span_diagnostic.struct_span_fatal(syntax_pos::mk_sp(from_pos, to_pos), &m[..]) self.sess.span_diagnostic.struct_span_fatal(syntax_pos::mk_sp(from_pos, to_pos), &m[..])
} }
/// Report a lexical error spanning [`from_pos`, `to_pos`), appending an /// Report a lexical error spanning [`from_pos`, `to_pos`), appending an
@ -298,7 +291,7 @@ impl<'a> StringReader<'a> {
for c in c.escape_default() { for c in c.escape_default() {
m.push(c) m.push(c)
} }
self.span_diagnostic.struct_span_err(syntax_pos::mk_sp(from_pos, to_pos), &m[..]) self.sess.span_diagnostic.struct_span_err(syntax_pos::mk_sp(from_pos, to_pos), &m[..])
} }
/// Report a lexical error spanning [`from_pos`, `to_pos`), appending the /// Report a lexical error spanning [`from_pos`, `to_pos`), appending the
@ -503,9 +496,8 @@ impl<'a> StringReader<'a> {
fn scan_comment(&mut self) -> Option<TokenAndSpan> { fn scan_comment(&mut self) -> Option<TokenAndSpan> {
if let Some(c) = self.ch { if let Some(c) = self.ch {
if c.is_whitespace() { if c.is_whitespace() {
self.span_diagnostic.span_err(syntax_pos::mk_sp(self.pos, self.pos), let msg = "called consume_any_line_comment, but there was whitespace";
"called consume_any_line_comment, but there \ self.sess.span_diagnostic.span_err(syntax_pos::mk_sp(self.pos, self.pos), msg);
was whitespace");
} }
} }
@ -875,7 +867,7 @@ impl<'a> StringReader<'a> {
self.scan_unicode_escape(delim) && !ascii_only self.scan_unicode_escape(delim) && !ascii_only
} else { } else {
let span = syntax_pos::mk_sp(start, self.pos); let span = syntax_pos::mk_sp(start, self.pos);
self.span_diagnostic self.sess.span_diagnostic
.struct_span_err(span, "incorrect unicode escape sequence") .struct_span_err(span, "incorrect unicode escape sequence")
.span_help(span, .span_help(span,
"format of unicode escape sequences is \ "format of unicode escape sequences is \
@ -1701,35 +1693,41 @@ fn ident_continue(c: Option<char>) -> bool {
mod tests { mod tests {
use super::*; use super::*;
use ast::Ident; use ast::{Ident, CrateConfig};
use symbol::Symbol; use symbol::Symbol;
use syntax_pos::{BytePos, Span, NO_EXPANSION}; use syntax_pos::{BytePos, Span, NO_EXPANSION};
use codemap::CodeMap; use codemap::CodeMap;
use errors; use errors;
use feature_gate::UnstableFeatures;
use parse::token; use parse::token;
use std::cell::RefCell;
use std::io; use std::io;
use std::rc::Rc; use std::rc::Rc;
fn mk_sh(cm: Rc<CodeMap>) -> errors::Handler { fn mk_sess(cm: Rc<CodeMap>) -> ParseSess {
// FIXME (#22405): Replace `Box::new` with `box` here when/if possible. let emitter = errors::emitter::EmitterWriter::new(Box::new(io::sink()), Some(cm.clone()));
let emitter = errors::emitter::EmitterWriter::new(Box::new(io::sink()), ParseSess {
Some(cm)); span_diagnostic: errors::Handler::with_emitter(true, false, Box::new(emitter)),
errors::Handler::with_emitter(true, false, Box::new(emitter)) unstable_features: UnstableFeatures::from_environment(),
config: CrateConfig::new(),
included_mod_stack: RefCell::new(Vec::new()),
code_map: cm,
}
} }
// open a string reader for the given string // open a string reader for the given string
fn setup<'a>(cm: &CodeMap, fn setup<'a>(cm: &CodeMap,
span_handler: &'a errors::Handler, sess: &'a ParseSess,
teststr: String) teststr: String)
-> StringReader<'a> { -> StringReader<'a> {
let fm = cm.new_filemap("zebra.rs".to_string(), None, teststr); let fm = cm.new_filemap("zebra.rs".to_string(), None, teststr);
StringReader::new(span_handler, fm) StringReader::new(sess, fm)
} }
#[test] #[test]
fn t1() { fn t1() {
let cm = Rc::new(CodeMap::new()); let cm = Rc::new(CodeMap::new());
let sh = mk_sh(cm.clone()); let sh = mk_sess(cm.clone());
let mut string_reader = setup(&cm, let mut string_reader = setup(&cm,
&sh, &sh,
"/* my source file */ fn main() { println!(\"zebra\"); }\n" "/* my source file */ fn main() { println!(\"zebra\"); }\n"
@ -1781,7 +1779,7 @@ mod tests {
#[test] #[test]
fn doublecolonparsing() { fn doublecolonparsing() {
let cm = Rc::new(CodeMap::new()); let cm = Rc::new(CodeMap::new());
let sh = mk_sh(cm.clone()); let sh = mk_sess(cm.clone());
check_tokenization(setup(&cm, &sh, "a b".to_string()), check_tokenization(setup(&cm, &sh, "a b".to_string()),
vec![mk_ident("a"), token::Whitespace, mk_ident("b")]); vec![mk_ident("a"), token::Whitespace, mk_ident("b")]);
} }
@ -1789,7 +1787,7 @@ mod tests {
#[test] #[test]
fn dcparsing_2() { fn dcparsing_2() {
let cm = Rc::new(CodeMap::new()); let cm = Rc::new(CodeMap::new());
let sh = mk_sh(cm.clone()); let sh = mk_sess(cm.clone());
check_tokenization(setup(&cm, &sh, "a::b".to_string()), check_tokenization(setup(&cm, &sh, "a::b".to_string()),
vec![mk_ident("a"), token::ModSep, mk_ident("b")]); vec![mk_ident("a"), token::ModSep, mk_ident("b")]);
} }
@ -1797,7 +1795,7 @@ mod tests {
#[test] #[test]
fn dcparsing_3() { fn dcparsing_3() {
let cm = Rc::new(CodeMap::new()); let cm = Rc::new(CodeMap::new());
let sh = mk_sh(cm.clone()); let sh = mk_sess(cm.clone());
check_tokenization(setup(&cm, &sh, "a ::b".to_string()), check_tokenization(setup(&cm, &sh, "a ::b".to_string()),
vec![mk_ident("a"), token::Whitespace, token::ModSep, mk_ident("b")]); vec![mk_ident("a"), token::Whitespace, token::ModSep, mk_ident("b")]);
} }
@ -1805,7 +1803,7 @@ mod tests {
#[test] #[test]
fn dcparsing_4() { fn dcparsing_4() {
let cm = Rc::new(CodeMap::new()); let cm = Rc::new(CodeMap::new());
let sh = mk_sh(cm.clone()); let sh = mk_sess(cm.clone());
check_tokenization(setup(&cm, &sh, "a:: b".to_string()), check_tokenization(setup(&cm, &sh, "a:: b".to_string()),
vec![mk_ident("a"), token::ModSep, token::Whitespace, mk_ident("b")]); vec![mk_ident("a"), token::ModSep, token::Whitespace, mk_ident("b")]);
} }
@ -1813,7 +1811,7 @@ mod tests {
#[test] #[test]
fn character_a() { fn character_a() {
let cm = Rc::new(CodeMap::new()); let cm = Rc::new(CodeMap::new());
let sh = mk_sh(cm.clone()); let sh = mk_sess(cm.clone());
assert_eq!(setup(&cm, &sh, "'a'".to_string()).next_token().tok, assert_eq!(setup(&cm, &sh, "'a'".to_string()).next_token().tok,
token::Literal(token::Char(Symbol::intern("a")), None)); token::Literal(token::Char(Symbol::intern("a")), None));
} }
@ -1821,7 +1819,7 @@ mod tests {
#[test] #[test]
fn character_space() { fn character_space() {
let cm = Rc::new(CodeMap::new()); let cm = Rc::new(CodeMap::new());
let sh = mk_sh(cm.clone()); let sh = mk_sess(cm.clone());
assert_eq!(setup(&cm, &sh, "' '".to_string()).next_token().tok, assert_eq!(setup(&cm, &sh, "' '".to_string()).next_token().tok,
token::Literal(token::Char(Symbol::intern(" ")), None)); token::Literal(token::Char(Symbol::intern(" ")), None));
} }
@ -1829,7 +1827,7 @@ mod tests {
#[test] #[test]
fn character_escaped() { fn character_escaped() {
let cm = Rc::new(CodeMap::new()); let cm = Rc::new(CodeMap::new());
let sh = mk_sh(cm.clone()); let sh = mk_sess(cm.clone());
assert_eq!(setup(&cm, &sh, "'\\n'".to_string()).next_token().tok, assert_eq!(setup(&cm, &sh, "'\\n'".to_string()).next_token().tok,
token::Literal(token::Char(Symbol::intern("\\n")), None)); token::Literal(token::Char(Symbol::intern("\\n")), None));
} }
@ -1837,7 +1835,7 @@ mod tests {
#[test] #[test]
fn lifetime_name() { fn lifetime_name() {
let cm = Rc::new(CodeMap::new()); let cm = Rc::new(CodeMap::new());
let sh = mk_sh(cm.clone()); let sh = mk_sess(cm.clone());
assert_eq!(setup(&cm, &sh, "'abc".to_string()).next_token().tok, assert_eq!(setup(&cm, &sh, "'abc".to_string()).next_token().tok,
token::Lifetime(Ident::from_str("'abc"))); token::Lifetime(Ident::from_str("'abc")));
} }
@ -1845,7 +1843,7 @@ mod tests {
#[test] #[test]
fn raw_string() { fn raw_string() {
let cm = Rc::new(CodeMap::new()); let cm = Rc::new(CodeMap::new());
let sh = mk_sh(cm.clone()); let sh = mk_sess(cm.clone());
assert_eq!(setup(&cm, &sh, "r###\"\"#a\\b\x00c\"\"###".to_string()) assert_eq!(setup(&cm, &sh, "r###\"\"#a\\b\x00c\"\"###".to_string())
.next_token() .next_token()
.tok, .tok,
@ -1855,7 +1853,7 @@ mod tests {
#[test] #[test]
fn literal_suffixes() { fn literal_suffixes() {
let cm = Rc::new(CodeMap::new()); let cm = Rc::new(CodeMap::new());
let sh = mk_sh(cm.clone()); let sh = mk_sess(cm.clone());
macro_rules! test { macro_rules! test {
($input: expr, $tok_type: ident, $tok_contents: expr) => {{ ($input: expr, $tok_type: ident, $tok_contents: expr) => {{
assert_eq!(setup(&cm, &sh, format!("{}suffix", $input)).next_token().tok, assert_eq!(setup(&cm, &sh, format!("{}suffix", $input)).next_token().tok,
@ -1899,7 +1897,7 @@ mod tests {
#[test] #[test]
fn nested_block_comments() { fn nested_block_comments() {
let cm = Rc::new(CodeMap::new()); let cm = Rc::new(CodeMap::new());
let sh = mk_sh(cm.clone()); let sh = mk_sess(cm.clone());
let mut lexer = setup(&cm, &sh, "/* /* */ */'a'".to_string()); let mut lexer = setup(&cm, &sh, "/* /* */ */'a'".to_string());
match lexer.next_token().tok { match lexer.next_token().tok {
token::Comment => {} token::Comment => {}
@ -1912,7 +1910,7 @@ mod tests {
#[test] #[test]
fn crlf_comments() { fn crlf_comments() {
let cm = Rc::new(CodeMap::new()); let cm = Rc::new(CodeMap::new());
let sh = mk_sh(cm.clone()); let sh = mk_sess(cm.clone());
let mut lexer = setup(&cm, &sh, "// test\r\n/// test\r\n".to_string()); let mut lexer = setup(&cm, &sh, "// test\r\n/// test\r\n".to_string());
let comment = lexer.next_token(); let comment = lexer.next_token();
assert_eq!(comment.tok, token::Comment); assert_eq!(comment.tok, token::Comment);

View File

@ -243,10 +243,8 @@ pub fn check_for_substitution<'a>(reader: &StringReader<'a>,
err.span_help(span, &msg); err.span_help(span, &msg);
}, },
None => { None => {
reader let msg = format!("substitution character not found for '{}'", ch);
.span_diagnostic reader.sess.span_diagnostic.span_bug_no_panic(span, &msg);
.span_bug_no_panic(span,
&format!("substitution character not found for '{}'", ch));
} }
} }
}); });

View File

@ -223,7 +223,7 @@ pub fn filemap_to_tts(sess: &ParseSess, filemap: Rc<FileMap>)
-> Vec<tokenstream::TokenTree> { -> Vec<tokenstream::TokenTree> {
// it appears to me that the cfg doesn't matter here... indeed, // it appears to me that the cfg doesn't matter here... indeed,
// parsing tt's probably shouldn't require a parser at all. // parsing tt's probably shouldn't require a parser at all.
let srdr = lexer::StringReader::new(&sess.span_diagnostic, filemap); let srdr = lexer::StringReader::new(sess, filemap);
let mut p1 = Parser::new(sess, Box::new(srdr), None, false); let mut p1 = Parser::new(sess, Box::new(srdr), None, false);
panictry!(p1.parse_all_token_trees()) panictry!(p1.parse_all_token_trees())
} }

View File

@ -18,10 +18,9 @@ use util::parser::AssocOp;
use attr; use attr;
use codemap::{self, CodeMap}; use codemap::{self, CodeMap};
use syntax_pos::{self, BytePos}; use syntax_pos::{self, BytePos};
use errors;
use parse::token::{self, BinOpToken, Token}; use parse::token::{self, BinOpToken, Token};
use parse::lexer::comments; use parse::lexer::comments;
use parse; use parse::{self, ParseSess};
use print::pp::{self, break_offset, word, space, zerobreak, hardbreak}; use print::pp::{self, break_offset, word, space, zerobreak, hardbreak};
use print::pp::{Breaks, eof}; use print::pp::{Breaks, eof};
use print::pp::Breaks::{Consistent, Inconsistent}; use print::pp::Breaks::{Consistent, Inconsistent};
@ -101,20 +100,15 @@ pub const DEFAULT_COLUMNS: usize = 78;
/// it can scan the input text for comments and literals to /// it can scan the input text for comments and literals to
/// copy forward. /// copy forward.
pub fn print_crate<'a>(cm: &'a CodeMap, pub fn print_crate<'a>(cm: &'a CodeMap,
span_diagnostic: &errors::Handler, sess: &ParseSess,
krate: &ast::Crate, krate: &ast::Crate,
filename: String, filename: String,
input: &mut Read, input: &mut Read,
out: Box<Write+'a>, out: Box<Write+'a>,
ann: &'a PpAnn, ann: &'a PpAnn,
is_expanded: bool) -> io::Result<()> { is_expanded: bool) -> io::Result<()> {
let mut s = State::new_from_input(cm, let mut s = State::new_from_input(cm, sess, filename, input, out, ann, is_expanded);
span_diagnostic,
filename,
input,
out,
ann,
is_expanded);
if is_expanded && !std_inject::injected_crate_name(krate).is_none() { if is_expanded && !std_inject::injected_crate_name(krate).is_none() {
// We need to print `#![no_std]` (and its feature gate) so that // We need to print `#![no_std]` (and its feature gate) so that
// compiling pretty-printed source won't inject libstd again. // compiling pretty-printed source won't inject libstd again.
@ -140,16 +134,13 @@ pub fn print_crate<'a>(cm: &'a CodeMap,
impl<'a> State<'a> { impl<'a> State<'a> {
pub fn new_from_input(cm: &'a CodeMap, pub fn new_from_input(cm: &'a CodeMap,
span_diagnostic: &errors::Handler, sess: &ParseSess,
filename: String, filename: String,
input: &mut Read, input: &mut Read,
out: Box<Write+'a>, out: Box<Write+'a>,
ann: &'a PpAnn, ann: &'a PpAnn,
is_expanded: bool) -> State<'a> { is_expanded: bool) -> State<'a> {
let (cmnts, lits) = comments::gather_comments_and_literals( let (cmnts, lits) = comments::gather_comments_and_literals(sess, filename, input);
span_diagnostic,
filename,
input);
State::new( State::new(
cm, cm,