|
|
@ -44,19 +44,19 @@ Value Parser::parse() |
|
|
|
Token token = peek(); |
|
|
|
Token token = peek(); |
|
|
|
switch (token.type) { |
|
|
|
switch (token.type) { |
|
|
|
case Token::Type::Literal: |
|
|
|
case Token::Type::Literal: |
|
|
|
result = getLiteral(); |
|
|
|
result = consumeLiteral(); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case Token::Type::Number: |
|
|
|
case Token::Type::Number: |
|
|
|
result = getNumber(); |
|
|
|
result = consumeNumber(); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case Token::Type::String: |
|
|
|
case Token::Type::String: |
|
|
|
result = getString(); |
|
|
|
result = consumeString(); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case Token::Type::BracketOpen: |
|
|
|
case Token::Type::BracketOpen: |
|
|
|
result = getArray(); |
|
|
|
result = consumeArray(); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case Token::Type::BraceOpen: |
|
|
|
case Token::Type::BraceOpen: |
|
|
|
result = getObject(); |
|
|
|
result = consumeObject(); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case Token::Type::BracketClose: |
|
|
|
case Token::Type::BracketClose: |
|
|
|
m_job->printErrorLine(token, "expecting value, not ']'"); |
|
|
|
m_job->printErrorLine(token, "expecting value, not ']'"); |
|
|
@ -110,7 +110,7 @@ Token Parser::consume() |
|
|
|
return token; |
|
|
|
return token; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Value Parser::getLiteral() |
|
|
|
Value Parser::consumeLiteral() |
|
|
|
{ |
|
|
|
{ |
|
|
|
Token token = consume(); |
|
|
|
Token token = consume(); |
|
|
|
|
|
|
|
|
|
|
@ -128,7 +128,7 @@ Value Parser::getLiteral() |
|
|
|
return nullptr; |
|
|
|
return nullptr; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Value Parser::getNumber() |
|
|
|
Value Parser::consumeNumber() |
|
|
|
{ |
|
|
|
{ |
|
|
|
Token token = consume(); |
|
|
|
Token token = consume(); |
|
|
|
|
|
|
|
|
|
|
@ -231,7 +231,7 @@ Value Parser::getNumber() |
|
|
|
return std::stod(token.symbol); |
|
|
|
return std::stod(token.symbol); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Value Parser::getString() |
|
|
|
Value Parser::consumeString() |
|
|
|
{ |
|
|
|
{ |
|
|
|
Token token = consume(); |
|
|
|
Token token = consume(); |
|
|
|
|
|
|
|
|
|
|
@ -305,7 +305,7 @@ Value Parser::getString() |
|
|
|
return string; |
|
|
|
return string; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Value Parser::getArray() |
|
|
|
Value Parser::consumeArray() |
|
|
|
{ |
|
|
|
{ |
|
|
|
m_index++; |
|
|
|
m_index++; |
|
|
|
|
|
|
|
|
|
|
@ -327,19 +327,19 @@ Value Parser::getArray() |
|
|
|
|
|
|
|
|
|
|
|
token = peek(); |
|
|
|
token = peek(); |
|
|
|
if (token.type == Token::Type::Literal) { |
|
|
|
if (token.type == Token::Type::Literal) { |
|
|
|
array.emplace_back(getLiteral()); |
|
|
|
array.emplace_back(consumeLiteral()); |
|
|
|
} |
|
|
|
} |
|
|
|
else if (token.type == Token::Type::Number) { |
|
|
|
else if (token.type == Token::Type::Number) { |
|
|
|
array.emplace_back(getNumber()); |
|
|
|
array.emplace_back(consumeNumber()); |
|
|
|
} |
|
|
|
} |
|
|
|
else if (token.type == Token::Type::String) { |
|
|
|
else if (token.type == Token::Type::String) { |
|
|
|
array.emplace_back(getString()); |
|
|
|
array.emplace_back(consumeString()); |
|
|
|
} |
|
|
|
} |
|
|
|
else if (token.type == Token::Type::BracketOpen) { |
|
|
|
else if (token.type == Token::Type::BracketOpen) { |
|
|
|
array.emplace_back(getArray()); |
|
|
|
array.emplace_back(consumeArray()); |
|
|
|
} |
|
|
|
} |
|
|
|
else if (token.type == Token::Type::BraceOpen) { |
|
|
|
else if (token.type == Token::Type::BraceOpen) { |
|
|
|
array.emplace_back(getObject()); |
|
|
|
array.emplace_back(consumeObject()); |
|
|
|
} |
|
|
|
} |
|
|
|
else if (token.type == Token::Type::BracketClose) { |
|
|
|
else if (token.type == Token::Type::BracketClose) { |
|
|
|
// Trailing comma
|
|
|
|
// Trailing comma
|
|
|
@ -376,7 +376,7 @@ Value Parser::getArray() |
|
|
|
return array; |
|
|
|
return array; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Value Parser::getObject() |
|
|
|
Value Parser::consumeObject() |
|
|
|
{ |
|
|
|
{ |
|
|
|
m_index++; |
|
|
|
m_index++; |
|
|
|
|
|
|
|
|
|
|
@ -414,7 +414,7 @@ Value Parser::getObject() |
|
|
|
|
|
|
|
|
|
|
|
// Find member name
|
|
|
|
// Find member name
|
|
|
|
m_index--; |
|
|
|
m_index--; |
|
|
|
Value tmpName = getString(); |
|
|
|
Value tmpName = consumeString(); |
|
|
|
if (tmpName.m_type != Value::Type::String) { |
|
|
|
if (tmpName.m_type != Value::Type::String) { |
|
|
|
seekForward(Token::Type::BraceClose); |
|
|
|
seekForward(Token::Type::BraceClose); |
|
|
|
break; |
|
|
|
break; |
|
|
@ -453,19 +453,19 @@ Value Parser::getObject() |
|
|
|
// Add member (name:value pair) to object
|
|
|
|
// Add member (name:value pair) to object
|
|
|
|
token = peek(); |
|
|
|
token = peek(); |
|
|
|
if (token.type == Token::Type::Literal) { |
|
|
|
if (token.type == Token::Type::Literal) { |
|
|
|
object.emplace(name, getLiteral()); |
|
|
|
object.emplace(name, consumeLiteral()); |
|
|
|
} |
|
|
|
} |
|
|
|
else if (token.type == Token::Type::Number) { |
|
|
|
else if (token.type == Token::Type::Number) { |
|
|
|
object.emplace(name, getNumber()); |
|
|
|
object.emplace(name, consumeNumber()); |
|
|
|
} |
|
|
|
} |
|
|
|
else if (token.type == Token::Type::String) { |
|
|
|
else if (token.type == Token::Type::String) { |
|
|
|
object.emplace(name, getString()); |
|
|
|
object.emplace(name, consumeString()); |
|
|
|
} |
|
|
|
} |
|
|
|
else if (token.type == Token::Type::BracketOpen) { |
|
|
|
else if (token.type == Token::Type::BracketOpen) { |
|
|
|
object.emplace(name, getArray()); |
|
|
|
object.emplace(name, consumeArray()); |
|
|
|
} |
|
|
|
} |
|
|
|
else if (token.type == Token::Type::BraceOpen) { |
|
|
|
else if (token.type == Token::Type::BraceOpen) { |
|
|
|
object.emplace(name, getObject()); |
|
|
|
object.emplace(name, consumeObject()); |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else { |
|
|
|
reportError(token, "expecting value, not '" + token.symbol + "'"); |
|
|
|
reportError(token, "expecting value, not '" + token.symbol + "'"); |
|
|
|