Skip to content

Commit 3a9ccd5

Browse files
committed
Factor out some position management code in the lexer
1 parent 8069d2f commit 3a9ccd5

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/libsyntax/codemap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ pub impl FileMap {
189189
return FileMap {
190190
name: filename, substr: substr, src: src,
191191
start_pos: start_pos,
192-
mut lines: ~[start_pos]
192+
mut lines: ~[]
193193
};
194194
}
195195

src/libsyntax/parse/lexer.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,17 @@ fn new_low_level_string_reader(span_diagnostic: span_handler,
4545
filemap: @codemap::FileMap,
4646
itr: @token::ident_interner)
4747
-> string_reader {
48+
// Force the initial reader bump to start on a fresh line
49+
let initial_char = '\n';
4850
let r = @{span_diagnostic: span_diagnostic, src: filemap.src,
49-
mut col: CharPos(0), mut pos: BytePos(0), mut curr: -1 as char,
51+
mut col: CharPos(0), mut pos: BytePos(0),
52+
mut curr: initial_char,
5053
mut chpos: filemap.start_pos.ch,
5154
filemap: filemap, interner: itr,
5255
/* dummy values; not read */
5356
mut peek_tok: token::EOF,
5457
mut peek_span: ast_util::dummy_sp()};
55-
if r.pos.to_uint() < (*filemap.src).len() {
56-
let next = str::char_range_at(*r.src, r.pos.to_uint());
57-
r.pos = BytePos(next.next);
58-
r.curr = next.ch;
59-
}
58+
bump(r);
6059
return r;
6160
}
6261

@@ -142,9 +141,10 @@ fn bump(rdr: string_reader) {
142141
rdr.pos = BytePos(next.next);
143142
rdr.curr = next.ch;
144143
} else {
144+
// XXX: What does this accomplish?
145145
if (rdr.curr != -1 as char) {
146-
rdr.col += CharPos(1u);
147146
rdr.chpos += CharPos(1u);
147+
rdr.col += CharPos(1u);
148148
rdr.curr = -1 as char;
149149
}
150150
}

0 commit comments

Comments
 (0)