Commit d6b8830e by Niels

more work on exceptions (#160)

parent dc8ab925
...@@ -398,7 +398,7 @@ $ make ...@@ -398,7 +398,7 @@ $ make
$ ./json_unit "*" $ ./json_unit "*"
=============================================================================== ===============================================================================
All tests passed (3341947 assertions in 28 test cases) All tests passed (3343239 assertions in 28 test cases)
``` ```
For more information, have a look at the file [.travis.yml](https://github.com/nlohmann/json/blob/master/.travis.yml). For more information, have a look at the file [.travis.yml](https://github.com/nlohmann/json/blob/master/.travis.yml).
...@@ -6459,21 +6459,21 @@ class basic_json ...@@ -6459,21 +6459,21 @@ class basic_json
case token_type::value_number: case token_type::value_number:
return "number literal"; return "number literal";
case token_type::begin_array: case token_type::begin_array:
return "["; return "'['";
case token_type::begin_object: case token_type::begin_object:
return "{"; return "'{'";
case token_type::end_array: case token_type::end_array:
return "]"; return "']'";
case token_type::end_object: case token_type::end_object:
return "}"; return "'}'";
case token_type::name_separator: case token_type::name_separator:
return ":"; return "':'";
case token_type::value_separator: case token_type::value_separator:
return ","; return "','";
case token_type::parse_error: case token_type::parse_error:
return "<parse error>"; return "<parse error>";
case token_type::end_of_input: case token_type::end_of_input:
return "<end of input>"; return "end of input";
default: default:
{ {
// catch non-enum values // catch non-enum values
...@@ -7752,10 +7752,10 @@ basic_json_parser_64: ...@@ -7752,10 +7752,10 @@ basic_json_parser_64:
{ {
if (t != last_token) if (t != last_token)
{ {
std::string error_msg = "parse error - unexpected \'"; std::string error_msg = "parse error - unexpected ";
error_msg += m_lexer.get_token(); error_msg += (last_token == lexer::token_type::parse_error ? ("'" + m_lexer.get_token() + "'") :
error_msg += "\' (" + lexer::token_type_name(last_token); lexer::token_type_name(last_token));
error_msg += "); expected " + lexer::token_type_name(t); error_msg += "; expected " + lexer::token_type_name(t);
throw std::invalid_argument(error_msg); throw std::invalid_argument(error_msg);
} }
} }
...@@ -7764,9 +7764,9 @@ basic_json_parser_64: ...@@ -7764,9 +7764,9 @@ basic_json_parser_64:
{ {
if (t == last_token) if (t == last_token)
{ {
std::string error_msg = "parse error - unexpected \'"; std::string error_msg = "parse error - unexpected ";
error_msg += m_lexer.get_token(); error_msg += (last_token == lexer::token_type::parse_error ? ("'" + m_lexer.get_token() + "'") :
error_msg += "\'"; lexer::token_type_name(last_token));
throw std::invalid_argument(error_msg); throw std::invalid_argument(error_msg);
} }
} }
......
...@@ -6441,7 +6441,7 @@ class basic_json ...@@ -6441,7 +6441,7 @@ class basic_json
return result; return result;
} }
/// return name of values of type token_type /// return name of values of type token_type (only used for errors)
static std::string token_type_name(token_type t) static std::string token_type_name(token_type t)
{ {
switch (t) switch (t)
...@@ -6459,21 +6459,21 @@ class basic_json ...@@ -6459,21 +6459,21 @@ class basic_json
case token_type::value_number: case token_type::value_number:
return "number literal"; return "number literal";
case token_type::begin_array: case token_type::begin_array:
return "["; return "'['";
case token_type::begin_object: case token_type::begin_object:
return "{"; return "'{'";
case token_type::end_array: case token_type::end_array:
return "]"; return "']'";
case token_type::end_object: case token_type::end_object:
return "}"; return "'}'";
case token_type::name_separator: case token_type::name_separator:
return ":"; return "':'";
case token_type::value_separator: case token_type::value_separator:
return ","; return "','";
case token_type::parse_error: case token_type::parse_error:
return "<parse error>"; return "<parse error>";
case token_type::end_of_input: case token_type::end_of_input:
return "<end of input>"; return "end of input";
default: default:
{ {
// catch non-enum values // catch non-enum values
...@@ -7031,10 +7031,10 @@ class basic_json ...@@ -7031,10 +7031,10 @@ class basic_json
{ {
if (t != last_token) if (t != last_token)
{ {
std::string error_msg = "parse error - unexpected \'"; std::string error_msg = "parse error - unexpected ";
error_msg += m_lexer.get_token(); error_msg += (last_token == lexer::token_type::parse_error ? ("'" + m_lexer.get_token() + "'") :
error_msg += "\' (" + lexer::token_type_name(last_token); lexer::token_type_name(last_token));
error_msg += "); expected " + lexer::token_type_name(t); error_msg += "; expected " + lexer::token_type_name(t);
throw std::invalid_argument(error_msg); throw std::invalid_argument(error_msg);
} }
} }
...@@ -7043,9 +7043,9 @@ class basic_json ...@@ -7043,9 +7043,9 @@ class basic_json
{ {
if (t == last_token) if (t == last_token)
{ {
std::string error_msg = "parse error - unexpected \'"; std::string error_msg = "parse error - unexpected ";
error_msg += m_lexer.get_token(); error_msg += (last_token == lexer::token_type::parse_error ? ("'" + m_lexer.get_token() + "'") :
error_msg += "\'"; lexer::token_type_name(last_token));
throw std::invalid_argument(error_msg); throw std::invalid_argument(error_msg);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment