diff options
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/comments.rs | 16 | ||||
| -rw-r--r-- | src/libsyntax/parse/lexer.rs | 30 |
2 files changed, 18 insertions, 28 deletions
diff --git a/src/libsyntax/parse/comments.rs b/src/libsyntax/parse/comments.rs index 589a5f25ecf..e3ac3e7dcbb 100644 --- a/src/libsyntax/parse/comments.rs +++ b/src/libsyntax/parse/comments.rs @@ -131,7 +131,7 @@ fn consume_non_eol_whitespace(rdr: string_reader) { fn push_blank_line_comment(rdr: string_reader, comments: &mut ~[cmnt]) { debug!(">>> blank-line comment"); let v: ~[~str] = ~[]; - comments.push({style: blank_line, lines: v, pos: rdr.last_pos.byte}); + comments.push({style: blank_line, lines: v, pos: rdr.last_pos}); } fn consume_whitespace_counting_blank_lines(rdr: string_reader, @@ -148,7 +148,7 @@ fn consume_whitespace_counting_blank_lines(rdr: string_reader, fn read_shebang_comment(rdr: string_reader, code_to_the_left: bool, comments: &mut ~[cmnt]) { debug!(">>> shebang comment"); - let p = rdr.last_pos.byte; + let p = rdr.last_pos; debug!("<<< shebang comment"); comments.push({ style: if code_to_the_left { trailing } else { isolated }, @@ -160,7 +160,7 @@ fn read_shebang_comment(rdr: string_reader, code_to_the_left: bool, fn read_line_comments(rdr: string_reader, code_to_the_left: bool, comments: &mut ~[cmnt]) { debug!(">>> line comments"); - let p = rdr.last_pos.byte; + let p = rdr.last_pos; let mut lines: ~[~str] = ~[]; while rdr.curr == '/' && nextch(rdr) == '/' { let line = read_one_line_comment(rdr); @@ -209,7 +209,7 @@ fn trim_whitespace_prefix_and_push_line(lines: &mut ~[~str], fn read_block_comment(rdr: string_reader, code_to_the_left: bool, comments: &mut ~[cmnt]) { debug!(">>> block comment"); - let p = rdr.last_pos.byte; + let p = rdr.last_pos; let mut lines: ~[~str] = ~[]; let mut col: CharPos = rdr.col; bump(rdr); @@ -292,11 +292,7 @@ fn gather_comments_and_literals(span_diagnostic: diagnostic::span_handler, {cmnts: ~[cmnt], lits: ~[lit]} { let src = @str::from_bytes(srdr.read_whole_stream()); let itr = parse::token::mk_fake_ident_interner(); - let filemap = @FileMap::new(path, src, - FilePos { - ch: CharPos(0u), - byte: BytePos(0u) - }); + let filemap = @FileMap::new(path, src, BytePos(0)); let rdr = lexer::new_low_level_string_reader( span_diagnostic, filemap, itr); @@ -319,7 +315,7 @@ fn gather_comments_and_literals(span_diagnostic: diagnostic::span_handler, } - let bstart = rdr.pos.byte; + let bstart = rdr.pos; rdr.next_token(); //discard, and look ahead; we're working with internal state let {tok: tok, sp: sp} = rdr.peek(); diff --git a/src/libsyntax/parse/lexer.rs b/src/libsyntax/parse/lexer.rs index 00a0b40ab65..10a74d620a3 100644 --- a/src/libsyntax/parse/lexer.rs +++ b/src/libsyntax/parse/lexer.rs @@ -22,9 +22,9 @@ type string_reader = @{ span_diagnostic: span_handler, src: @~str, // The absolute offset within the codemap of the next character to read - mut pos: FilePos, + mut pos: BytePos, // The absolute offset within the codemap of the last character read(curr) - mut last_pos: FilePos, + mut last_pos: BytePos, // The column of the next character to read mut col: CharPos, // The last character to be read @@ -123,15 +123,15 @@ fn string_advance_token(&&r: string_reader) { if is_eof(r) { r.peek_tok = token::EOF; } else { - let start_bytepos = r.last_pos.byte; + let start_bytepos = r.last_pos; r.peek_tok = next_token_inner(r); - r.peek_span = ast_util::mk_sp(start_bytepos, r.last_pos.byte); + r.peek_span = ast_util::mk_sp(start_bytepos, r.last_pos); }; } fn byte_offset(rdr: string_reader) -> BytePos { - (rdr.pos.byte - rdr.filemap.start_pos.byte) + (rdr.pos - rdr.filemap.start_pos) } fn get_str_from(rdr: string_reader, start: BytePos) -> ~str unsafe { @@ -148,10 +148,7 @@ fn bump(rdr: string_reader) { let last_char = rdr.curr; let next = str::char_range_at(*rdr.src, current_byte_offset); let byte_offset_diff = next.next - current_byte_offset; - rdr.pos = FilePos { - ch: rdr.pos.ch + CharPos(1u), - byte: rdr.pos.byte + BytePos(byte_offset_diff) - }; + rdr.pos = rdr.pos + BytePos(byte_offset_diff); rdr.curr = next.ch; rdr.col += CharPos(1u); if last_char == '\n' { @@ -166,10 +163,7 @@ fn bump(rdr: string_reader) { } else { // XXX: What does this accomplish? if (rdr.curr != -1 as char) { - rdr.pos = FilePos { - ch: rdr.pos.ch + CharPos(1u), - byte: rdr.pos.byte + BytePos(1u) - }; + rdr.pos = rdr.pos + BytePos(1u); rdr.col += CharPos(1u); rdr.curr = -1 as char; } @@ -238,7 +232,7 @@ fn consume_any_line_comment(rdr: string_reader) bump(rdr); // line comments starting with "///" or "//!" are doc-comments if rdr.curr == '/' || rdr.curr == '!' { - let start_bpos = rdr.pos.byte - BytePos(2u); + let start_bpos = rdr.pos - BytePos(2u); let mut acc = ~"//"; while rdr.curr != '\n' && !is_eof(rdr) { str::push_char(&mut acc, rdr.curr); @@ -246,7 +240,7 @@ fn consume_any_line_comment(rdr: string_reader) } return Some({ tok: token::DOC_COMMENT(rdr.interner.intern(@acc)), - sp: ast_util::mk_sp(start_bpos, rdr.pos.byte) + sp: ast_util::mk_sp(start_bpos, rdr.pos) }); } else { while rdr.curr != '\n' && !is_eof(rdr) { bump(rdr); } @@ -261,7 +255,7 @@ fn consume_any_line_comment(rdr: string_reader) if nextch(rdr) == '!' { let cmap = @CodeMap::new(); (*cmap).files.push(rdr.filemap); - let loc = cmap.lookup_char_pos_adj(rdr.last_pos.byte); + let loc = cmap.lookup_char_pos_adj(rdr.last_pos); if loc.line == 1u && loc.col == CharPos(0u) { while rdr.curr != '\n' && !is_eof(rdr) { bump(rdr); } return consume_whitespace_and_comments(rdr); @@ -277,7 +271,7 @@ fn consume_block_comment(rdr: string_reader) // block comments starting with "/**" or "/*!" are doc-comments if rdr.curr == '*' || rdr.curr == '!' { - let start_bpos = rdr.pos.byte - BytePos(2u); + let start_bpos = rdr.pos - BytePos(2u); let mut acc = ~"/*"; while !(rdr.curr == '*' && nextch(rdr) == '/') && !is_eof(rdr) { str::push_char(&mut acc, rdr.curr); @@ -291,7 +285,7 @@ fn consume_block_comment(rdr: string_reader) bump(rdr); return Some({ tok: token::DOC_COMMENT(rdr.interner.intern(@acc)), - sp: ast_util::mk_sp(start_bpos, rdr.pos.byte) + sp: ast_util::mk_sp(start_bpos, rdr.pos) }); } } else { |
