diff options
| author | Brian Anderson <banderson@mozilla.com> | 2012-11-12 19:32:48 -0800 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2012-11-14 15:18:29 -0800 |
| commit | f67bfe97389a256fc95216c29a2b8a066ee16a2c (patch) | |
| tree | a638c4c480ceb60138a39a05c5b04967ac814eb6 /src/libsyntax/parse/comments.rs | |
| parent | 9ecf86343a136c71cbb2bb8da9bfd1734fec37f4 (diff) | |
| download | rust-f67bfe97389a256fc95216c29a2b8a066ee16a2c.tar.gz rust-f67bfe97389a256fc95216c29a2b8a066ee16a2c.zip | |
Add types for character position and byte position in the codemap
Diffstat (limited to 'src/libsyntax/parse/comments.rs')
| -rw-r--r-- | src/libsyntax/parse/comments.rs | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/src/libsyntax/parse/comments.rs b/src/libsyntax/parse/comments.rs index a2f73fd189c..06b042a468a 100644 --- a/src/libsyntax/parse/comments.rs +++ b/src/libsyntax/parse/comments.rs @@ -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] = ~[]; |
