rustc: Replace the lexer's error handling with diagnostic impl
This commit is contained in:
parent
e90701c546
commit
f4bd03b998
@ -285,7 +285,7 @@ fn ann_identified_post(node: pprust::ann_node) {
|
||||
}
|
||||
ppm_normal. { ann = pprust::no_ann(); }
|
||||
}
|
||||
pprust::print_crate(sess.codemap, crate, input,
|
||||
pprust::print_crate(sess.codemap, sess.diagnostic, crate, input,
|
||||
io::string_reader(src), io::stdout(), ann);
|
||||
}
|
||||
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
type reader = @{
|
||||
cm: codemap::codemap,
|
||||
diagnostic: diagnostic::handler,
|
||||
src: str,
|
||||
len: uint,
|
||||
mutable col: uint,
|
||||
@ -48,14 +49,18 @@ fn bump() {
|
||||
} else { self.curr = -1 as char; }
|
||||
}
|
||||
fn err(m: str) {
|
||||
diagnostic::emit_error(
|
||||
some((self.cm, ast_util::mk_sp(self.chpos, self.chpos))), m);
|
||||
self.diagnostic.span_err(
|
||||
ast_util::mk_sp(self.chpos, self.chpos),
|
||||
m);
|
||||
}
|
||||
}
|
||||
|
||||
fn new_reader(cm: codemap::codemap, src: str, filemap: codemap::filemap,
|
||||
fn new_reader(cm: codemap::codemap,
|
||||
diagnostic: diagnostic::handler,
|
||||
src: str, filemap: codemap::filemap,
|
||||
itr: @interner::interner<str>) -> reader {
|
||||
let r = @{cm: cm, src: src, len: str::byte_len(src),
|
||||
let r = @{cm: cm, diagnostic: diagnostic,
|
||||
src: src, len: str::byte_len(src),
|
||||
mutable col: 0u, mutable pos: 0u, mutable curr: -1 as char,
|
||||
mutable chpos: filemap.start_pos.ch, mutable strs: [],
|
||||
filemap: filemap, interner: itr};
|
||||
@ -666,12 +671,15 @@ fn is_lit(t: token::token) -> bool {
|
||||
|
||||
type lit = {lit: str, pos: uint};
|
||||
|
||||
fn gather_comments_and_literals(cm: codemap::codemap, path: str,
|
||||
fn gather_comments_and_literals(cm: codemap::codemap,
|
||||
diagnostic: diagnostic::handler,
|
||||
path: str,
|
||||
srdr: io::reader) ->
|
||||
{cmnts: [cmnt], lits: [lit]} {
|
||||
let src = str::unsafe_from_bytes(srdr.read_whole_stream());
|
||||
let itr = @interner::mk::<str>(str::hash, str::eq);
|
||||
let rdr = new_reader(cm, src, codemap::new_filemap(path, 0u, 0u), itr);
|
||||
let rdr = new_reader(cm, diagnostic, src,
|
||||
codemap::new_filemap(path, 0u, 0u), itr);
|
||||
let comments: [cmnt] = [];
|
||||
let literals: [lit] = [];
|
||||
let first_read: bool = true;
|
||||
|
@ -102,7 +102,8 @@ fn new_parser_from_file(sess: parse_sess, cfg: ast::crate_cfg, path: str,
|
||||
let filemap = codemap::new_filemap(path, chpos, byte_pos);
|
||||
sess.cm.files += [filemap];
|
||||
let itr = @interner::mk(str::hash, str::eq);
|
||||
let rdr = lexer::new_reader(sess.cm, src, filemap, itr);
|
||||
let rdr = lexer::new_reader(sess.cm, sess.diagnostic,
|
||||
src, filemap, itr);
|
||||
ret new_parser(sess, cfg, rdr, ftype);
|
||||
}
|
||||
|
||||
@ -112,7 +113,8 @@ fn new_parser_from_source_str(sess: parse_sess, cfg: ast::crate_cfg,
|
||||
let filemap = codemap::new_filemap(name, 0u, 0u);
|
||||
sess.cm.files += [filemap];
|
||||
let itr = @interner::mk(str::hash, str::eq);
|
||||
let rdr = lexer::new_reader(sess.cm, source, filemap, itr);
|
||||
let rdr = lexer::new_reader(sess.cm, sess.diagnostic,
|
||||
source, filemap, itr);
|
||||
ret new_parser(sess, cfg, rdr, ftype);
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,7 @@
|
||||
import pp::{break_offset, word, printer,
|
||||
space, zerobreak, hardbreak, breaks, consistent,
|
||||
inconsistent, eof};
|
||||
import driver::diagnostic;
|
||||
|
||||
// The ps is stored here to prevent recursive type.
|
||||
// FIXME use a nominal tag instead
|
||||
@ -59,10 +60,11 @@ fn rust_printer(writer: io::writer) -> ps {
|
||||
// Requires you to pass an input filename and reader so that
|
||||
// it can scan the input text for comments and literals to
|
||||
// copy forward.
|
||||
fn print_crate(cm: codemap, crate: @ast::crate, filename: str, in: io::reader,
|
||||
fn print_crate(cm: codemap, diagnostic: diagnostic::handler,
|
||||
crate: @ast::crate, filename: str, in: io::reader,
|
||||
out: io::writer, ann: pp_ann) {
|
||||
let boxes: [pp::breaks] = [];
|
||||
let r = lexer::gather_comments_and_literals(cm, filename, in);
|
||||
let r = lexer::gather_comments_and_literals(cm, diagnostic, filename, in);
|
||||
let s =
|
||||
@{s: pp::mk_printer(out, default_columns),
|
||||
cm: some(cm),
|
||||
|
Loading…
Reference in New Issue
Block a user