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

Loading…
Cancel
Save