From aa5b5117ad30a7b4b8391bd527170dd26764a365 Mon Sep 17 00:00:00 2001 From: Riyyi Date: Tue, 12 Jul 2022 01:40:57 +0200 Subject: [PATCH] Util: Change seekForward() to go 1 step after the match --- src/util/json/parser.cpp | 25 ++++--------------------- src/util/json/parser.h | 1 - 2 files changed, 4 insertions(+), 22 deletions(-) diff --git a/src/util/json/parser.cpp b/src/util/json/parser.cpp index 504e1d7..49d992a 100644 --- a/src/util/json/parser.cpp +++ b/src/util/json/parser.cpp @@ -93,9 +93,9 @@ Token Parser::peek() bool Parser::seekForward(Token::Type type) { - for (size_t index = m_index; index < m_tokens->size(); ++index) { - if (m_tokens->at(index).type == type) { - m_index = index; + for (; !reachedEnd(); ++m_index) { + if (peek().type == type) { + m_index++; return true; } } @@ -110,20 +110,6 @@ Token Parser::consume() return token; } -bool Parser::consumeSpecific(Token::Type type) -{ - if (reachedEnd()) { - return false; - } - - if (peek().type != type) { - return false; - } - - m_index++; - return true; -} - Value Parser::getLiteral() { Token token = consume(); @@ -323,7 +309,6 @@ Value Parser::getArray() // After an error, try to find the closing bracket seekForward(Token::Type::BracketClose); - consumeSpecific(Token::Type::BracketClose); }; Value array = Value::Type::Array; @@ -393,9 +378,8 @@ Value Parser::getObject() auto reportError = [this](Token token, const std::string& message) -> void { m_job->printErrorLine(token, message.c_str()); - // After an error, try to find the closing bracket + // After an error, try to find the closing brace seekForward(Token::Type::BraceClose); - consumeSpecific(Token::Type::BraceClose); }; Value object = Value::Type::Object; @@ -427,7 +411,6 @@ Value Parser::getObject() Value tmpName = getString(); if (tmpName.type() != Value::Type::String) { seekForward(Token::Type::BraceClose); - consumeSpecific(Token::Type::BraceClose); break; } diff --git a/src/util/json/parser.h b/src/util/json/parser.h index f286ae4..74c41e8 100644 --- a/src/util/json/parser.h +++ b/src/util/json/parser.h @@ -31,7 +31,6 @@ private: bool seekForward(Token::Type type); Token consume(); - bool consumeSpecific(Token::Type type); Value getLiteral(); Value getNumber();