From 62c58a076c1a33cae265f77fe54f974bff12f630 Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Tue, 26 Jul 2022 14:59:54 +0000 Subject: [PATCH] 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 Commit-Queue: Ben Clayton Auto-Submit: Dan Sinclair Kokoro: Kokoro --- src/tint/reader/wgsl/parser_impl.cc | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/tint/reader/wgsl/parser_impl.cc b/src/tint/reader/wgsl/parser_impl.cc index 7f8edd2421..f3473ff84e 100644 --- a/src/tint/reader/wgsl/parser_impl.cc +++ b/src/tint/reader/wgsl/parser_impl.cc @@ -275,14 +275,17 @@ 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()) { - // Skip over any placeholder elements - while (true) { - if (!tokens_[next_token_idx_].IsPlaceholder()) { - break; - } - next_token_idx_++; + // 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()) { + break; } + next_token_idx_++; } last_source_idx_ = next_token_idx_; return tokens_[next_token_idx_++];