Browse Source

Util: Properly detect empty Tokens and multiple root elements

master
Riyyi 2 years ago
parent
commit
abb075939f
  1. 12
      src/util/json/parser.cpp

12
src/util/json/parser.cpp

@ -36,17 +36,18 @@ Value Parser::parse()
{
Value result;
Token token;
while (m_index < m_tokens->size()) {
token = peek();
if (m_tokens->size() == 0) {
m_job->printErrorLine({}, "expecting token, not 'EOF'");
return result;
}
Token token = peek();
switch (token.type) {
case Token::Type::Literal:
result = getLiteral();
break;
case Token::Type::Number:
result = getNumber();
m_index++;
break;
case Token::Type::String:
result = getString();
@ -70,6 +71,9 @@ Value Parser::parse()
m_index++;
break;
}
if (m_index < m_tokens->size()) {
m_job->printErrorLine(peek(), "multiple root elements");
}
return result;

Loading…
Cancel
Save