Rename Parser::expected_tokens as Parser::expected_token_types.

Because the `Token` type is similar to but different to the `TokenType`
type, and the difference is important, so we want to avoid confusion.
This commit is contained in:
Nicholas Nethercote
2024-12-03 20:09:29 +11:00
parent c434b4b4b6
commit 48f7714819
7 changed files with 26 additions and 25 deletions

View File

@@ -141,7 +141,7 @@ pub struct Parser<'a> {
pub prev_token: Token,
pub capture_cfg: bool,
restrictions: Restrictions,
expected_tokens: Vec<TokenType>,
expected_token_types: Vec<TokenType>,
token_cursor: TokenCursor,
// The number of calls to `bump`, i.e. the position in the token stream.
num_bump_calls: u32,
@@ -490,7 +490,7 @@ impl<'a> Parser<'a> {
prev_token: Token::dummy(),
capture_cfg: false,
restrictions: Restrictions::empty(),
expected_tokens: Vec::new(),
expected_token_types: Vec::new(),
token_cursor: TokenCursor { curr: TokenTreeCursor::new(stream), stack: Vec::new() },
num_bump_calls: 0,
break_last_token: 0,
@@ -554,7 +554,7 @@ impl<'a> Parser<'a> {
/// Expects and consumes the token `t`. Signals an error if the next token is not `t`.
pub fn expect(&mut self, t: &TokenKind) -> PResult<'a, Recovered> {
if self.expected_tokens.is_empty() {
if self.expected_token_types.is_empty() {
if self.token == *t {
self.bump();
Ok(Recovered::No)
@@ -619,13 +619,13 @@ impl<'a> Parser<'a> {
/// Checks if the next token is `tok`, and returns `true` if so.
///
/// This method will automatically add `tok` to `expected_tokens` if `tok` is not
/// This method will automatically add `tok` to `expected_token_types` if `tok` is not
/// encountered.
#[inline]
fn check(&mut self, tok: &TokenKind) -> bool {
let is_present = self.token == *tok;
if !is_present {
self.expected_tokens.push(TokenType::Token(tok.clone()));
self.expected_token_types.push(TokenType::Token(tok.clone()));
}
is_present
}
@@ -666,7 +666,7 @@ impl<'a> Parser<'a> {
#[inline]
#[must_use]
fn check_keyword(&mut self, kw: Symbol) -> bool {
self.expected_tokens.push(TokenType::Keyword(kw));
self.expected_token_types.push(TokenType::Keyword(kw));
self.token.is_keyword(kw)
}
@@ -755,7 +755,7 @@ impl<'a> Parser<'a> {
if ok {
true
} else {
self.expected_tokens.push(typ);
self.expected_token_types.push(typ);
false
}
}
@@ -832,7 +832,7 @@ impl<'a> Parser<'a> {
true
}
_ => {
self.expected_tokens.push(TokenType::Token(expected));
self.expected_token_types.push(TokenType::Token(expected));
false
}
}
@@ -1180,7 +1180,7 @@ impl<'a> Parser<'a> {
self.token_spacing = next_spacing;
// Diagnostics.
self.expected_tokens.clear();
self.expected_token_types.clear();
}
/// Advance the parser by one token.
@@ -1670,8 +1670,8 @@ impl<'a> Parser<'a> {
DebugParser { parser: self, lookahead }
}
pub fn clear_expected_tokens(&mut self) {
self.expected_tokens.clear();
pub fn clear_expected_token_types(&mut self) {
self.expected_token_types.clear();
}
pub fn approx_token_stream_pos(&self) -> u32 {