🔨 removed unexpect function
This commit is contained in:
parent
2fd214c14b
commit
6f3bebff5c
3 changed files with 28 additions and 28 deletions
24
src/json.hpp
24
src/json.hpp
|
@ -11132,7 +11132,8 @@ class basic_json
|
||||||
name_separator, ///< the name separator `:`
|
name_separator, ///< the name separator `:`
|
||||||
value_separator, ///< the value separator `,`
|
value_separator, ///< the value separator `,`
|
||||||
parse_error, ///< indicating a parse error
|
parse_error, ///< indicating a parse error
|
||||||
end_of_input ///< indicating the end of the input buffer
|
end_of_input, ///< indicating the end of the input buffer
|
||||||
|
literal_or_value ///< a literal or the begin of a value (only for diagnostics)
|
||||||
};
|
};
|
||||||
|
|
||||||
/// return name of values of type token_type (only used for errors)
|
/// return name of values of type token_type (only used for errors)
|
||||||
|
@ -11170,6 +11171,8 @@ class basic_json
|
||||||
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";
|
||||||
|
case token_type::literal_or_value:
|
||||||
|
return "'[', '{', or a literal";
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
// catch non-enum values
|
// catch non-enum values
|
||||||
|
@ -12903,10 +12906,16 @@ scan_number_done:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case lexer::token_type::parse_error:
|
||||||
|
{
|
||||||
|
// using "uninitialized" to avoid "expected" message
|
||||||
|
expect(lexer::token_type::uninitialized);
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
// the last token was unexpected
|
// we expected a value
|
||||||
unexpect();
|
expect(lexer::token_type::literal_or_value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13060,15 +13069,6 @@ scan_number_done:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
|
||||||
@throw parse_error.101 if unexpected token occurred
|
|
||||||
*/
|
|
||||||
void unexpect()
|
|
||||||
{
|
|
||||||
errored = true;
|
|
||||||
throw_exception();
|
|
||||||
}
|
|
||||||
|
|
||||||
[[noreturn]] void throw_exception() const
|
[[noreturn]] void throw_exception() const
|
||||||
{
|
{
|
||||||
std::string error_msg = "syntax error - ";
|
std::string error_msg = "syntax error - ";
|
||||||
|
|
|
@ -694,15 +694,15 @@ TEST_CASE("parser class")
|
||||||
CHECK_THROWS_AS(json::parser(json::input_adapter::create(std::string("[1,]"))).parse(), json::parse_error);
|
CHECK_THROWS_AS(json::parser(json::input_adapter::create(std::string("[1,]"))).parse(), json::parse_error);
|
||||||
CHECK_THROWS_AS(json::parser(json::input_adapter::create(std::string("]"))).parse(), json::parse_error);
|
CHECK_THROWS_AS(json::parser(json::input_adapter::create(std::string("]"))).parse(), json::parse_error);
|
||||||
CHECK_THROWS_WITH(json::parser(json::input_adapter::create(std::string("["))).parse(),
|
CHECK_THROWS_WITH(json::parser(json::input_adapter::create(std::string("["))).parse(),
|
||||||
"[json.exception.parse_error.101] parse error at 2: syntax error - unexpected end of input");
|
"[json.exception.parse_error.101] parse error at 2: syntax error - unexpected end of input; expected '[', '{', or a literal");
|
||||||
CHECK_THROWS_WITH(json::parser(json::input_adapter::create(std::string("[1"))).parse(),
|
CHECK_THROWS_WITH(json::parser(json::input_adapter::create(std::string("[1"))).parse(),
|
||||||
"[json.exception.parse_error.101] parse error at 3: syntax error - unexpected end of input; expected ']'");
|
"[json.exception.parse_error.101] parse error at 3: syntax error - unexpected end of input; expected ']'");
|
||||||
CHECK_THROWS_WITH(json::parser(json::input_adapter::create(std::string("[1,"))).parse(),
|
CHECK_THROWS_WITH(json::parser(json::input_adapter::create(std::string("[1,"))).parse(),
|
||||||
"[json.exception.parse_error.101] parse error at 4: syntax error - unexpected end of input");
|
"[json.exception.parse_error.101] parse error at 4: syntax error - unexpected end of input; expected '[', '{', or a literal");
|
||||||
CHECK_THROWS_WITH(json::parser(json::input_adapter::create(std::string("[1,]"))).parse(),
|
CHECK_THROWS_WITH(json::parser(json::input_adapter::create(std::string("[1,]"))).parse(),
|
||||||
"[json.exception.parse_error.101] parse error at 4: syntax error - unexpected ']'");
|
"[json.exception.parse_error.101] parse error at 4: syntax error - unexpected ']'; expected '[', '{', or a literal");
|
||||||
CHECK_THROWS_WITH(json::parser(json::input_adapter::create(std::string("]"))).parse(),
|
CHECK_THROWS_WITH(json::parser(json::input_adapter::create(std::string("]"))).parse(),
|
||||||
"[json.exception.parse_error.101] parse error at 1: syntax error - unexpected ']'");
|
"[json.exception.parse_error.101] parse error at 1: syntax error - unexpected ']'; expected '[', '{', or a literal");
|
||||||
|
|
||||||
// missing/unexpected end of object
|
// missing/unexpected end of object
|
||||||
CHECK_THROWS_AS(json::parser(json::input_adapter::create(std::string("{"))).parse(), json::parse_error);
|
CHECK_THROWS_AS(json::parser(json::input_adapter::create(std::string("{"))).parse(), json::parse_error);
|
||||||
|
@ -716,13 +716,13 @@ TEST_CASE("parser class")
|
||||||
CHECK_THROWS_WITH(json::parser(json::input_adapter::create(std::string("{\"foo\""))).parse(),
|
CHECK_THROWS_WITH(json::parser(json::input_adapter::create(std::string("{\"foo\""))).parse(),
|
||||||
"[json.exception.parse_error.101] parse error at 7: syntax error - unexpected end of input; expected ':'");
|
"[json.exception.parse_error.101] parse error at 7: syntax error - unexpected end of input; expected ':'");
|
||||||
CHECK_THROWS_WITH(json::parser(json::input_adapter::create(std::string("{\"foo\":"))).parse(),
|
CHECK_THROWS_WITH(json::parser(json::input_adapter::create(std::string("{\"foo\":"))).parse(),
|
||||||
"[json.exception.parse_error.101] parse error at 8: syntax error - unexpected end of input");
|
"[json.exception.parse_error.101] parse error at 8: syntax error - unexpected end of input; expected '[', '{', or a literal");
|
||||||
CHECK_THROWS_WITH(json::parser(json::input_adapter::create(std::string("{\"foo\":}"))).parse(),
|
CHECK_THROWS_WITH(json::parser(json::input_adapter::create(std::string("{\"foo\":}"))).parse(),
|
||||||
"[json.exception.parse_error.101] parse error at 8: syntax error - unexpected '}'");
|
"[json.exception.parse_error.101] parse error at 8: syntax error - unexpected '}'; expected '[', '{', or a literal");
|
||||||
CHECK_THROWS_WITH(json::parser(json::input_adapter::create(std::string("{\"foo\":1,}"))).parse(),
|
CHECK_THROWS_WITH(json::parser(json::input_adapter::create(std::string("{\"foo\":1,}"))).parse(),
|
||||||
"[json.exception.parse_error.101] parse error at 10: syntax error - unexpected '}'; expected string literal");
|
"[json.exception.parse_error.101] parse error at 10: syntax error - unexpected '}'; expected string literal");
|
||||||
CHECK_THROWS_WITH(json::parser(json::input_adapter::create(std::string("}"))).parse(),
|
CHECK_THROWS_WITH(json::parser(json::input_adapter::create(std::string("}"))).parse(),
|
||||||
"[json.exception.parse_error.101] parse error at 1: syntax error - unexpected '}'");
|
"[json.exception.parse_error.101] parse error at 1: syntax error - unexpected '}'; expected '[', '{', or a literal");
|
||||||
|
|
||||||
// missing/unexpected end of string
|
// missing/unexpected end of string
|
||||||
CHECK_THROWS_AS(json::parser(json::input_adapter::create(std::string("\""))).parse(), json::parse_error);
|
CHECK_THROWS_AS(json::parser(json::input_adapter::create(std::string("\""))).parse(), json::parse_error);
|
||||||
|
|
|
@ -597,7 +597,7 @@ TEST_CASE("regression tests")
|
||||||
// a parse error because of the EOF.
|
// a parse error because of the EOF.
|
||||||
CHECK_THROWS_AS(ss >> j, json::parse_error);
|
CHECK_THROWS_AS(ss >> j, json::parse_error);
|
||||||
CHECK_THROWS_WITH(ss >> j,
|
CHECK_THROWS_WITH(ss >> j,
|
||||||
"[json.exception.parse_error.101] parse error at 1: syntax error - unexpected end of input");
|
"[json.exception.parse_error.101] parse error at 1: syntax error - unexpected end of input; expected '[', '{', or a literal");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("issue #367 - behavior of operator>> should more closely resemble that of built-in overloads")
|
SECTION("issue #367 - behavior of operator>> should more closely resemble that of built-in overloads")
|
||||||
|
@ -608,7 +608,7 @@ TEST_CASE("regression tests")
|
||||||
json j;
|
json j;
|
||||||
CHECK_THROWS_AS(ss >> j, json::parse_error);
|
CHECK_THROWS_AS(ss >> j, json::parse_error);
|
||||||
CHECK_THROWS_WITH(ss >> j,
|
CHECK_THROWS_WITH(ss >> j,
|
||||||
"[json.exception.parse_error.101] parse error at 1: syntax error - unexpected end of input");
|
"[json.exception.parse_error.101] parse error at 1: syntax error - unexpected end of input; expected '[', '{', or a literal");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("(whitespace)")
|
SECTION("(whitespace)")
|
||||||
|
@ -618,7 +618,7 @@ TEST_CASE("regression tests")
|
||||||
json j;
|
json j;
|
||||||
CHECK_THROWS_AS(ss >> j, json::parse_error);
|
CHECK_THROWS_AS(ss >> j, json::parse_error);
|
||||||
CHECK_THROWS_WITH(ss >> j,
|
CHECK_THROWS_WITH(ss >> j,
|
||||||
"[json.exception.parse_error.101] parse error at 1: syntax error - unexpected end of input");
|
"[json.exception.parse_error.101] parse error at 1: syntax error - unexpected end of input; expected '[', '{', or a literal");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("one value")
|
SECTION("one value")
|
||||||
|
@ -631,7 +631,7 @@ TEST_CASE("regression tests")
|
||||||
|
|
||||||
CHECK_THROWS_AS(ss >> j, json::parse_error);
|
CHECK_THROWS_AS(ss >> j, json::parse_error);
|
||||||
CHECK_THROWS_WITH(ss >> j,
|
CHECK_THROWS_WITH(ss >> j,
|
||||||
"[json.exception.parse_error.101] parse error at 1: syntax error - unexpected end of input");
|
"[json.exception.parse_error.101] parse error at 1: syntax error - unexpected end of input; expected '[', '{', or a literal");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("one value + whitespace")
|
SECTION("one value + whitespace")
|
||||||
|
@ -644,7 +644,7 @@ TEST_CASE("regression tests")
|
||||||
|
|
||||||
CHECK_THROWS_AS(ss >> j, json::parse_error);
|
CHECK_THROWS_AS(ss >> j, json::parse_error);
|
||||||
CHECK_THROWS_WITH(ss >> j,
|
CHECK_THROWS_WITH(ss >> j,
|
||||||
"[json.exception.parse_error.101] parse error at 1: syntax error - unexpected end of input");
|
"[json.exception.parse_error.101] parse error at 1: syntax error - unexpected end of input; expected '[', '{', or a literal");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("whitespace + one value")
|
SECTION("whitespace + one value")
|
||||||
|
@ -657,7 +657,7 @@ TEST_CASE("regression tests")
|
||||||
|
|
||||||
CHECK_THROWS_AS(ss >> j, json::parse_error);
|
CHECK_THROWS_AS(ss >> j, json::parse_error);
|
||||||
CHECK_THROWS_WITH(ss >> j,
|
CHECK_THROWS_WITH(ss >> j,
|
||||||
"[json.exception.parse_error.101] parse error at 1: syntax error - unexpected end of input");
|
"[json.exception.parse_error.101] parse error at 1: syntax error - unexpected end of input; expected '[', '{', or a literal");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("three values")
|
SECTION("three values")
|
||||||
|
@ -674,7 +674,7 @@ TEST_CASE("regression tests")
|
||||||
|
|
||||||
CHECK_THROWS_AS(ss >> j, json::parse_error);
|
CHECK_THROWS_AS(ss >> j, json::parse_error);
|
||||||
CHECK_THROWS_WITH(ss >> j,
|
CHECK_THROWS_WITH(ss >> j,
|
||||||
"[json.exception.parse_error.101] parse error at 1: syntax error - unexpected end of input");
|
"[json.exception.parse_error.101] parse error at 1: syntax error - unexpected end of input; expected '[', '{', or a literal");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("literals without whitespace")
|
SECTION("literals without whitespace")
|
||||||
|
@ -693,7 +693,7 @@ TEST_CASE("regression tests")
|
||||||
|
|
||||||
CHECK_THROWS_AS(ss >> j, json::parse_error);
|
CHECK_THROWS_AS(ss >> j, json::parse_error);
|
||||||
CHECK_THROWS_WITH(ss >> j,
|
CHECK_THROWS_WITH(ss >> j,
|
||||||
"[json.exception.parse_error.101] parse error at 1: syntax error - unexpected end of input");
|
"[json.exception.parse_error.101] parse error at 1: syntax error - unexpected end of input; expected '[', '{', or a literal");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("example from #529")
|
SECTION("example from #529")
|
||||||
|
@ -708,7 +708,7 @@ TEST_CASE("regression tests")
|
||||||
|
|
||||||
CHECK_THROWS_AS(ss >> j, json::parse_error);
|
CHECK_THROWS_AS(ss >> j, json::parse_error);
|
||||||
CHECK_THROWS_WITH(ss >> j,
|
CHECK_THROWS_WITH(ss >> j,
|
||||||
"[json.exception.parse_error.101] parse error at 1: syntax error - unexpected end of input");
|
"[json.exception.parse_error.101] parse error at 1: syntax error - unexpected end of input; expected '[', '{', or a literal");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("second example from #529")
|
SECTION("second example from #529")
|
||||||
|
|
Loading…
Reference in a new issue