Skip to content

Commit

Permalink
Rename StringReader::pos as next_pos.
Browse files Browse the repository at this point in the history
This is a [breaking-change] for libsyntax.
  • Loading branch information
nnethercote committed Oct 4, 2016
1 parent 3c4c859 commit 94565a4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
34 changes: 17 additions & 17 deletions src/libsyntax/parse/lexer/mod.rs
Expand Up @@ -77,7 +77,7 @@ pub struct TokenAndSpan {
pub struct StringReader<'a> {
pub span_diagnostic: &'a Handler,
/// The absolute offset within the codemap of the next character to read
pub pos: BytePos,
pub next_pos: BytePos,
/// The absolute offset within the codemap of the last character read(curr)
pub last_pos: BytePos,
/// The column of the next character to read
Expand Down Expand Up @@ -107,7 +107,7 @@ impl<'a> Reader for StringReader<'a> {
}

match self.terminator {
Some(t) => self.pos > t,
Some(t) => self.next_pos > t,
None => false,
}
}
Expand Down Expand Up @@ -173,7 +173,7 @@ impl<'a> Reader for TtReader<'a> {
}

impl<'a> StringReader<'a> {
/// For comments.rs, which hackily pokes into pos and curr
/// For comments.rs, which hackily pokes into next_pos and curr
pub fn new_raw<'b>(span_diagnostic: &'b Handler,
filemap: Rc<syntax_pos::FileMap>)
-> StringReader<'b> {
Expand All @@ -195,7 +195,7 @@ impl<'a> StringReader<'a> {

StringReader {
span_diagnostic: span_diagnostic,
pos: filemap.start_pos,
next_pos: filemap.start_pos,
last_pos: filemap.start_pos,
col: CharPos(0),
curr: Some('\n'),
Expand Down Expand Up @@ -414,13 +414,13 @@ impl<'a> StringReader<'a> {
/// Advance the StringReader by one character. If a newline is
/// discovered, add it to the FileMap's list of line start offsets.
pub fn bump(&mut self) {
self.last_pos = self.pos;
let current_byte_offset = self.byte_offset(self.pos).to_usize();
self.last_pos = self.next_pos;
let current_byte_offset = self.byte_offset(self.next_pos).to_usize();
if current_byte_offset < self.source_text.len() {
let last_char = self.curr.unwrap();
let ch = char_at(&self.source_text, current_byte_offset);
let byte_offset_diff = ch.len_utf8();
self.pos = self.pos + Pos::from_usize(byte_offset_diff);
self.next_pos = self.next_pos + Pos::from_usize(byte_offset_diff);
self.curr = Some(ch);
self.col = self.col + CharPos(1);
if last_char == '\n' {
Expand All @@ -439,7 +439,7 @@ impl<'a> StringReader<'a> {
}

pub fn nextch(&self) -> Option<char> {
let offset = self.byte_offset(self.pos).to_usize();
let offset = self.byte_offset(self.next_pos).to_usize();
if offset < self.source_text.len() {
Some(char_at(&self.source_text, offset))
} else {
Expand All @@ -452,7 +452,7 @@ impl<'a> StringReader<'a> {
}

pub fn nextnextch(&self) -> Option<char> {
let offset = self.byte_offset(self.pos).to_usize();
let offset = self.byte_offset(self.next_pos).to_usize();
let s = &self.source_text[..];
if offset >= s.len() {
return None;
Expand Down Expand Up @@ -518,7 +518,7 @@ impl<'a> StringReader<'a> {
break;
} else if doc_comment {
self.err_span_(self.last_pos,
self.pos,
self.next_pos,
"bare CR not allowed in doc-comment");
}
}
Expand Down Expand Up @@ -695,7 +695,7 @@ impl<'a> StringReader<'a> {
// in range for the true radix
if c.unwrap().to_digit(real_radix).is_none() {
self.err_span_(self.last_pos,
self.pos,
self.next_pos,
&format!("invalid digit for a base {} literal", real_radix));
}
len += 1;
Expand Down Expand Up @@ -809,7 +809,7 @@ impl<'a> StringReader<'a> {
accum_int *= 16;
accum_int += c.to_digit(16).unwrap_or_else(|| {
self.err_span_char(self.last_pos,
self.pos,
self.next_pos,
"invalid character in numeric character escape",
c);

Expand Down Expand Up @@ -980,11 +980,11 @@ impl<'a> StringReader<'a> {
accum_int += c.to_digit(16).unwrap_or_else(|| {
if c == delim {
panic!(self.fatal_span_(self.last_pos,
self.pos,
self.next_pos,
"unterminated unicode escape (needed a `}`)"));
} else {
self.err_span_char(self.last_pos,
self.pos,
self.next_pos,
"invalid character in unicode escape",
c);
}
Expand Down Expand Up @@ -1022,7 +1022,7 @@ impl<'a> StringReader<'a> {
}
if self.scan_digits(10, 10) == 0 {
self.err_span_(self.last_pos,
self.pos,
self.next_pos,
"expected at least one digit in exponent")
}
}
Expand Down Expand Up @@ -1259,7 +1259,7 @@ impl<'a> StringReader<'a> {
// if we find one, then this is an invalid character literal
if self.curr_is('\'') {
panic!(self.fatal_span_verbose(
start_with_quote, self.pos,
start_with_quote, self.next_pos,
String::from("character literal may only contain one codepoint")));

}
Expand Down Expand Up @@ -1467,7 +1467,7 @@ impl<'a> StringReader<'a> {
}
c => {
let last_bpos = self.last_pos;
let bpos = self.pos;
let bpos = self.next_pos;
let mut err = self.struct_fatal_span_char(last_bpos,
bpos,
"unknown start of token",
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/parse/lexer/unicode_chars.rs
Expand Up @@ -234,7 +234,7 @@ pub fn check_for_substitution<'a>(reader: &StringReader<'a>,
.iter()
.find(|&&(c, _, _)| c == ch)
.map(|&(_, u_name, ascii_char)| {
let span = make_span(reader.last_pos, reader.pos);
let span = make_span(reader.last_pos, reader.next_pos);
match ASCII_ARRAY.iter().find(|&&(c, _)| c == ascii_char) {
Some(&(ascii_char, ascii_name)) => {
let msg =
Expand Down

0 comments on commit 94565a4

Please sign in to comment.