Stay at the EOF or Error token.

When the `next` token is requested, if we're already at EOF or Error
we can just return that token and stay at that index.

Bug: crbug:1347298
Change-Id: I1c31cf32a7030166c174d336455c7adabf97c6c9
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/97220
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Auto-Submit: Dan Sinclair <dsinclair@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
dan sinclair 2022-07-26 14:59:54 +00:00 committed by Dawn LUCI CQ
parent ee36e39296
commit 62c58a076c
1 changed files with 10 additions and 7 deletions

View File

@ -275,7 +275,11 @@ void ParserImpl::deprecated(const Source& source, const std::string& msg) {
}
const Token& ParserImpl::next() {
if (!tokens_[next_token_idx_].IsEof() && !tokens_[next_token_idx_].IsError()) {
// If the next token is already an error or the end of file, stay there.
if (tokens_[next_token_idx_].IsEof() || tokens_[next_token_idx_].IsError()) {
return tokens_[next_token_idx_];
}
// Skip over any placeholder elements
while (true) {
if (!tokens_[next_token_idx_].IsPlaceholder()) {
@ -283,7 +287,6 @@ const Token& ParserImpl::next() {
}
next_token_idx_++;
}
}
last_source_idx_ = next_token_idx_;
return tokens_[next_token_idx_++];
}