diff --git a/src/tint/reader/wgsl/parser_impl.cc b/src/tint/reader/wgsl/parser_impl.cc index b449e31db4..3adab59cc1 100644 --- a/src/tint/reader/wgsl/parser_impl.cc +++ b/src/tint/reader/wgsl/parser_impl.cc @@ -248,7 +248,11 @@ const Token& ParserImpl::next() { next_token_idx_++; } last_source_idx_ = next_token_idx_; - return tokens_[next_token_idx_++]; + + if (!tokens_[next_token_idx_].IsEof() && !tokens_[next_token_idx_].IsError()) { + next_token_idx_++; + } + return tokens_[last_source_idx_]; } const Token& ParserImpl::peek(size_t idx) { @@ -263,6 +267,9 @@ const Token& ParserImpl::peek(size_t idx) { } idx++; } + if (next_token_idx_ + idx >= tokens_.size()) { + return tokens_[tokens_.size() - 1]; + } return tokens_[next_token_idx_ + idx]; }