Add types for character position and byte position in the codemap
This commit is contained in:
@@ -3,7 +3,7 @@ use io::ReaderUtil;
|
||||
use util::interner;
|
||||
use lexer::{string_reader, bump, is_eof, nextch,
|
||||
is_whitespace, get_str_from, reader};
|
||||
use codemap::FileMap;
|
||||
use codemap::{FileMap, CharPos};
|
||||
|
||||
export cmnt;
|
||||
export lit;
|
||||
@@ -28,7 +28,7 @@ impl cmnt_style : cmp::Eq {
|
||||
}
|
||||
}
|
||||
|
||||
type cmnt = {style: cmnt_style, lines: ~[~str], pos: uint};
|
||||
type cmnt = {style: cmnt_style, lines: ~[~str], pos: CharPos};
|
||||
|
||||
fn is_doc_comment(s: ~str) -> bool {
|
||||
s.starts_with(~"///") ||
|
||||
@@ -137,7 +137,7 @@ fn push_blank_line_comment(rdr: string_reader, comments: &mut ~[cmnt]) {
|
||||
fn consume_whitespace_counting_blank_lines(rdr: string_reader,
|
||||
comments: &mut ~[cmnt]) {
|
||||
while is_whitespace(rdr.curr) && !is_eof(rdr) {
|
||||
if rdr.col == 0u && rdr.curr == '\n' {
|
||||
if rdr.col == CharPos(0u) && rdr.curr == '\n' {
|
||||
push_blank_line_comment(rdr, comments);
|
||||
}
|
||||
bump(rdr);
|
||||
@@ -181,6 +181,8 @@ fn read_line_comments(rdr: string_reader, code_to_the_left: bool,
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME #3961: This is not the right way to convert string byte
|
||||
// offsets to characters.
|
||||
fn all_whitespace(s: ~str, begin: uint, end: uint) -> bool {
|
||||
let mut i: uint = begin;
|
||||
while i != end {
|
||||
@@ -190,9 +192,11 @@ fn all_whitespace(s: ~str, begin: uint, end: uint) -> bool {
|
||||
}
|
||||
|
||||
fn trim_whitespace_prefix_and_push_line(lines: &mut ~[~str],
|
||||
s: ~str, col: uint) {
|
||||
s: ~str, col: CharPos) {
|
||||
let mut s1;
|
||||
let len = str::len(s);
|
||||
// FIXME #3961: Doing bytewise comparison and slicing with CharPos
|
||||
let col = col.to_uint();
|
||||
if all_whitespace(s, 0u, uint::min(len, col)) {
|
||||
if col < len {
|
||||
s1 = str::slice(s, col, len);
|
||||
@@ -207,7 +211,7 @@ fn read_block_comment(rdr: string_reader, code_to_the_left: bool,
|
||||
debug!(">>> block comment");
|
||||
let p = rdr.chpos;
|
||||
let mut lines: ~[~str] = ~[];
|
||||
let mut col: uint = rdr.col;
|
||||
let mut col: CharPos = rdr.col;
|
||||
bump(rdr);
|
||||
bump(rdr);
|
||||
|
||||
@@ -280,7 +284,7 @@ fn consume_comment(rdr: string_reader, code_to_the_left: bool,
|
||||
debug!("<<< consume comment");
|
||||
}
|
||||
|
||||
type lit = {lit: ~str, pos: uint};
|
||||
type lit = {lit: ~str, pos: CharPos};
|
||||
|
||||
fn gather_comments_and_literals(span_diagnostic: diagnostic::span_handler,
|
||||
path: ~str,
|
||||
@@ -289,7 +293,8 @@ fn gather_comments_and_literals(span_diagnostic: diagnostic::span_handler,
|
||||
let src = @str::from_bytes(srdr.read_whole_stream());
|
||||
let itr = parse::token::mk_fake_ident_interner();
|
||||
let rdr = lexer::new_low_level_string_reader
|
||||
(span_diagnostic, @FileMap::new(path, src, 0u, 0u), itr);
|
||||
(span_diagnostic, @FileMap::new(path, src,
|
||||
CharPos(0u), BytePos(0u)), itr);
|
||||
|
||||
let mut comments: ~[cmnt] = ~[];
|
||||
let mut literals: ~[lit] = ~[];
|
||||
|
||||
Reference in New Issue
Block a user