Util: Properly detect empty Tokens and multiple root elements
This commit is contained in:
+37
-33
@@ -36,40 +36,44 @@ 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;
|
||||||
|
}
|
||||||
|
|
||||||
switch (token.type) {
|
Token token = peek();
|
||||||
case Token::Type::Literal:
|
switch (token.type) {
|
||||||
result = getLiteral();
|
case Token::Type::Literal:
|
||||||
break;
|
result = getLiteral();
|
||||||
case Token::Type::Number:
|
break;
|
||||||
result = getNumber();
|
case Token::Type::Number:
|
||||||
m_index++;
|
result = getNumber();
|
||||||
break;
|
break;
|
||||||
case Token::Type::String:
|
case Token::Type::String:
|
||||||
result = getString();
|
result = getString();
|
||||||
break;
|
break;
|
||||||
case Token::Type::BracketOpen:
|
case Token::Type::BracketOpen:
|
||||||
result = getArray();
|
result = getArray();
|
||||||
break;
|
break;
|
||||||
case Token::Type::BraceOpen:
|
case Token::Type::BraceOpen:
|
||||||
result = getObject();
|
result = getObject();
|
||||||
break;
|
break;
|
||||||
case Token::Type::BracketClose:
|
case Token::Type::BracketClose:
|
||||||
m_job->printErrorLine(token, "expecting value, not ']'");
|
m_job->printErrorLine(token, "expecting value, not ']'");
|
||||||
m_index++;
|
m_index++;
|
||||||
break;
|
break;
|
||||||
case Token::Type::BraceClose:
|
case Token::Type::BraceClose:
|
||||||
m_job->printErrorLine(token, "expecting string, not '}'");
|
m_job->printErrorLine(token, "expecting string, not '}'");
|
||||||
m_index++;
|
m_index++;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
m_job->printErrorLine(token, "multiple root elements");
|
m_job->printErrorLine(token, "multiple root elements");
|
||||||
m_index++;
|
m_index++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (m_index < m_tokens->size()) {
|
||||||
|
m_job->printErrorLine(peek(), "multiple root elements");
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
Reference in New Issue
Block a user