|
|
@ -44,16 +44,7 @@ Value Parser::parse() |
|
|
|
|
|
|
|
|
|
|
|
switch (token.type) { |
|
|
|
switch (token.type) { |
|
|
|
case Token::Type::Literal: |
|
|
|
case Token::Type::Literal: |
|
|
|
if (token.symbol == "null") { |
|
|
|
result = getLiteral(); |
|
|
|
result = nullptr; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if (token.symbol == "true") { |
|
|
|
|
|
|
|
result = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if (token.symbol == "false") { |
|
|
|
|
|
|
|
result = false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
m_index++; |
|
|
|
|
|
|
|
break; |
|
|
|
break; |
|
|
|
case Token::Type::Number: |
|
|
|
case Token::Type::Number: |
|
|
|
result = getNumber(); |
|
|
|
result = getNumber(); |
|
|
@ -123,6 +114,24 @@ bool Parser::consumeSpecific(Token::Type type) |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Value Parser::getLiteral() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Token token = consume(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (token.symbol == "null") { |
|
|
|
|
|
|
|
return nullptr; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if (token.symbol == "true") { |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if (token.symbol == "false") { |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m_job->printErrorLine(token, "invalid literal"); |
|
|
|
|
|
|
|
return nullptr; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Value Parser::getNumber() |
|
|
|
Value Parser::getNumber() |
|
|
|
{ |
|
|
|
{ |
|
|
|
Token token = consume(); |
|
|
|
Token token = consume(); |
|
|
@ -238,16 +247,7 @@ Value Parser::getArray() |
|
|
|
|
|
|
|
|
|
|
|
if (token.type == Token::Type::Literal) { |
|
|
|
if (token.type == Token::Type::Literal) { |
|
|
|
printf("Adding literal to array.. v:{%s}, t:{%d}\n", token.symbol.c_str(), (int)token.type); |
|
|
|
printf("Adding literal to array.. v:{%s}, t:{%d}\n", token.symbol.c_str(), (int)token.type); |
|
|
|
if (token.symbol == "null") { |
|
|
|
array.emplace_back(getLiteral()); |
|
|
|
array.emplace_back(nullptr); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if (token.symbol == "true") { |
|
|
|
|
|
|
|
array.emplace_back(true); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if (token.symbol == "false") { |
|
|
|
|
|
|
|
array.emplace_back(false); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
m_index++; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
else if (token.type == Token::Type::Number) { |
|
|
|
else if (token.type == Token::Type::Number) { |
|
|
|
printf("Adding number to array.. v:{%s}, t:{%d} -> %f\n", token.symbol.c_str(), (int)token.type, std::stod(token.symbol)); |
|
|
|
printf("Adding number to array.. v:{%s}, t:{%d} -> %f\n", token.symbol.c_str(), (int)token.type, std::stod(token.symbol)); |
|
|
@ -345,15 +345,8 @@ Value Parser::getObject() |
|
|
|
token = consume(); |
|
|
|
token = consume(); |
|
|
|
if (token.type == Token::Type::Literal) { |
|
|
|
if (token.type == Token::Type::Literal) { |
|
|
|
printf("Adding literal to object.. k:{%s}, v:{%s}, t:{%d}\n", key.c_str(), token.symbol.c_str(), (int)token.type); |
|
|
|
printf("Adding literal to object.. k:{%s}, v:{%s}, t:{%d}\n", key.c_str(), token.symbol.c_str(), (int)token.type); |
|
|
|
if (token.symbol == "null") { |
|
|
|
m_index--; |
|
|
|
object[key] = nullptr; |
|
|
|
object[key] = getLiteral(); |
|
|
|
} |
|
|
|
|
|
|
|
else if (token.symbol == "true") { |
|
|
|
|
|
|
|
object[key] = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if (token.symbol == "false") { |
|
|
|
|
|
|
|
object[key] = false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
else if (token.type == Token::Type::Number) { |
|
|
|
else if (token.type == Token::Type::Number) { |
|
|
|
printf("Adding number to object.. k:{%s}, v:{%s}, t:{%d} -> %f\n", name.c_str(), token.symbol.c_str(), (int)token.type, std::stod(token.symbol)); |
|
|
|
printf("Adding number to object.. k:{%s}, v:{%s}, t:{%d} -> %f\n", name.c_str(), token.symbol.c_str(), (int)token.type, std::stod(token.symbol)); |
|
|
|