Browse Source

Util: Change seekForward() to go 1 step after the match

master
Riyyi 2 years ago
parent
commit
aa5b5117ad
  1. 25
      src/util/json/parser.cpp
  2. 1
      src/util/json/parser.h

25
src/util/json/parser.cpp

@ -93,9 +93,9 @@ Token Parser::peek()
bool Parser::seekForward(Token::Type type) bool Parser::seekForward(Token::Type type)
{ {
for (size_t index = m_index; index < m_tokens->size(); ++index) { for (; !reachedEnd(); ++m_index) {
if (m_tokens->at(index).type == type) { if (peek().type == type) {
m_index = index; m_index++;
return true; return true;
} }
} }
@ -110,20 +110,6 @@ Token Parser::consume()
return token; 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() Value Parser::getLiteral()
{ {
Token token = consume(); Token token = consume();
@ -323,7 +309,6 @@ Value Parser::getArray()
// After an error, try to find the closing bracket // After an error, try to find the closing bracket
seekForward(Token::Type::BracketClose); seekForward(Token::Type::BracketClose);
consumeSpecific(Token::Type::BracketClose);
}; };
Value array = Value::Type::Array; Value array = Value::Type::Array;
@ -393,9 +378,8 @@ Value Parser::getObject()
auto reportError = [this](Token token, const std::string& message) -> void { auto reportError = [this](Token token, const std::string& message) -> void {
m_job->printErrorLine(token, message.c_str()); 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); seekForward(Token::Type::BraceClose);
consumeSpecific(Token::Type::BraceClose);
}; };
Value object = Value::Type::Object; Value object = Value::Type::Object;
@ -427,7 +411,6 @@ Value Parser::getObject()
Value tmpName = getString(); Value tmpName = getString();
if (tmpName.type() != Value::Type::String) { if (tmpName.type() != Value::Type::String) {
seekForward(Token::Type::BraceClose); seekForward(Token::Type::BraceClose);
consumeSpecific(Token::Type::BraceClose);
break; break;
} }

1
src/util/json/parser.h

@ -31,7 +31,6 @@ private:
bool seekForward(Token::Type type); bool seekForward(Token::Type type);
Token consume(); Token consume();
bool consumeSpecific(Token::Type type);
Value getLiteral(); Value getLiteral();
Value getNumber(); Value getNumber();

Loading…
Cancel
Save