libsyntax: Remove the unnecessary src
field from the lexer
This commit is contained in:
parent
0327d8a073
commit
f152be7a42
1 changed files with 6 additions and 9 deletions
|
@ -42,7 +42,6 @@ pub struct TokenAndSpan {
|
||||||
|
|
||||||
pub struct StringReader {
|
pub struct StringReader {
|
||||||
span_diagnostic: @SpanHandler,
|
span_diagnostic: @SpanHandler,
|
||||||
src: @str,
|
|
||||||
// The absolute offset within the codemap of the next character to read
|
// The absolute offset within the codemap of the next character to read
|
||||||
pos: Cell<BytePos>,
|
pos: Cell<BytePos>,
|
||||||
// The absolute offset within the codemap of the last character read(curr)
|
// The absolute offset within the codemap of the last character read(curr)
|
||||||
|
@ -73,7 +72,6 @@ pub fn new_low_level_string_reader(span_diagnostic: @SpanHandler,
|
||||||
let initial_char = '\n';
|
let initial_char = '\n';
|
||||||
let r = @StringReader {
|
let r = @StringReader {
|
||||||
span_diagnostic: span_diagnostic,
|
span_diagnostic: span_diagnostic,
|
||||||
src: filemap.src,
|
|
||||||
pos: Cell::new(filemap.start_pos),
|
pos: Cell::new(filemap.start_pos),
|
||||||
last_pos: Cell::new(filemap.start_pos),
|
last_pos: Cell::new(filemap.start_pos),
|
||||||
col: Cell::new(CharPos(0)),
|
col: Cell::new(CharPos(0)),
|
||||||
|
@ -93,7 +91,6 @@ pub fn new_low_level_string_reader(span_diagnostic: @SpanHandler,
|
||||||
fn dup_string_reader(r: @StringReader) -> @StringReader {
|
fn dup_string_reader(r: @StringReader) -> @StringReader {
|
||||||
@StringReader {
|
@StringReader {
|
||||||
span_diagnostic: r.span_diagnostic,
|
span_diagnostic: r.span_diagnostic,
|
||||||
src: r.src,
|
|
||||||
pos: Cell::new(r.pos.get()),
|
pos: Cell::new(r.pos.get()),
|
||||||
last_pos: Cell::new(r.last_pos.get()),
|
last_pos: Cell::new(r.last_pos.get()),
|
||||||
col: Cell::new(r.col.get()),
|
col: Cell::new(r.col.get()),
|
||||||
|
@ -188,7 +185,7 @@ fn fatal_span_verbose(rdr: @StringReader,
|
||||||
-> ! {
|
-> ! {
|
||||||
let mut m = m;
|
let mut m = m;
|
||||||
m.push_str(": ");
|
m.push_str(": ");
|
||||||
let s = rdr.src.slice(
|
let s = rdr.filemap.src.slice(
|
||||||
byte_offset(rdr, from_pos).to_uint(),
|
byte_offset(rdr, from_pos).to_uint(),
|
||||||
byte_offset(rdr, to_pos).to_uint());
|
byte_offset(rdr, to_pos).to_uint());
|
||||||
m.push_str(s);
|
m.push_str(s);
|
||||||
|
@ -239,7 +236,7 @@ fn with_str_from_to<T>(
|
||||||
end: BytePos,
|
end: BytePos,
|
||||||
f: |s: &str| -> T)
|
f: |s: &str| -> T)
|
||||||
-> T {
|
-> T {
|
||||||
f(rdr.src.slice(
|
f(rdr.filemap.src.slice(
|
||||||
byte_offset(rdr, start).to_uint(),
|
byte_offset(rdr, start).to_uint(),
|
||||||
byte_offset(rdr, end).to_uint()))
|
byte_offset(rdr, end).to_uint()))
|
||||||
}
|
}
|
||||||
|
@ -249,12 +246,12 @@ fn with_str_from_to<T>(
|
||||||
pub fn bump(rdr: &StringReader) {
|
pub fn bump(rdr: &StringReader) {
|
||||||
rdr.last_pos.set(rdr.pos.get());
|
rdr.last_pos.set(rdr.pos.get());
|
||||||
let current_byte_offset = byte_offset(rdr, rdr.pos.get()).to_uint();
|
let current_byte_offset = byte_offset(rdr, rdr.pos.get()).to_uint();
|
||||||
if current_byte_offset < (rdr.src).len() {
|
if current_byte_offset < (rdr.filemap.src).len() {
|
||||||
assert!(rdr.curr.get() != unsafe {
|
assert!(rdr.curr.get() != unsafe {
|
||||||
transmute(-1u32)
|
transmute(-1u32)
|
||||||
}); // FIXME: #8971: unsound
|
}); // FIXME: #8971: unsound
|
||||||
let last_char = rdr.curr.get();
|
let last_char = rdr.curr.get();
|
||||||
let next = rdr.src.char_range_at(current_byte_offset);
|
let next = rdr.filemap.src.char_range_at(current_byte_offset);
|
||||||
let byte_offset_diff = next.next - current_byte_offset;
|
let byte_offset_diff = next.next - current_byte_offset;
|
||||||
rdr.pos.set(rdr.pos.get() + Pos::from_uint(byte_offset_diff));
|
rdr.pos.set(rdr.pos.get() + Pos::from_uint(byte_offset_diff));
|
||||||
rdr.curr.set(next.ch);
|
rdr.curr.set(next.ch);
|
||||||
|
@ -277,8 +274,8 @@ pub fn is_eof(rdr: @StringReader) -> bool {
|
||||||
}
|
}
|
||||||
pub fn nextch(rdr: @StringReader) -> char {
|
pub fn nextch(rdr: @StringReader) -> char {
|
||||||
let offset = byte_offset(rdr, rdr.pos.get()).to_uint();
|
let offset = byte_offset(rdr, rdr.pos.get()).to_uint();
|
||||||
if offset < (rdr.src).len() {
|
if offset < (rdr.filemap.src).len() {
|
||||||
return rdr.src.char_at(offset);
|
return rdr.filemap.src.char_at(offset);
|
||||||
} else { return unsafe { transmute(-1u32) }; } // FIXME: #8971: unsound
|
} else { return unsafe { transmute(-1u32) }; } // FIXME: #8971: unsound
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue