|
|
@ -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; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|