Util: Properly detect empty Tokens and multiple root elements
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user