Util: Properly detect empty Tokens and multiple root elements

This commit is contained in:
Riyyi
2022-07-11 19:08:30 +02:00
parent a3ab6aecfa
commit abb075939f
+8 -4
View File
@@ -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;