🚧 extend API

This commit is contained in:
Niels Lohmann 2020-06-17 22:03:14 +02:00
parent e9bfcf7255
commit 74520d8bb0
No known key found for this signature in database
GPG key ID: 7F3CEA63AE251B69
5 changed files with 148 additions and 66 deletions

View file

@ -837,6 +837,7 @@ class lexer : public lexer_base<BasicJsonType>
{ {
switch (get()) switch (get())
{ {
// single-line comments skip input until a newline or EOF is read
case '/': case '/':
{ {
while (true) while (true)
@ -845,6 +846,8 @@ class lexer : public lexer_base<BasicJsonType>
{ {
case '\n': case '\n':
case '\r': case '\r':
case std::char_traits<char_type>::eof():
case '\0':
return true; return true;
default: default:
@ -853,6 +856,7 @@ class lexer : public lexer_base<BasicJsonType>
} }
} }
// multi-line comments skip input until */ is read
case '*': case '*':
{ {
while (true) while (true)
@ -877,10 +881,14 @@ class lexer : public lexer_base<BasicJsonType>
} }
} }
} }
default:
break;
} }
} }
} }
// unexpected character after reading '/'
default: default:
return false; return false;
} }

View file

@ -63,8 +63,11 @@ class parser
/// a parser reading from an input adapter /// a parser reading from an input adapter
explicit parser(InputAdapterType&& adapter, explicit parser(InputAdapterType&& adapter,
const parser_callback_t<BasicJsonType> cb = nullptr, const parser_callback_t<BasicJsonType> cb = nullptr,
const bool allow_exceptions_ = true) const bool allow_exceptions_ = true,
: callback(cb), m_lexer(std::move(adapter)), allow_exceptions(allow_exceptions_) const bool skip_comments = false)
: callback(cb)
, m_lexer(std::move(adapter), skip_comments)
, allow_exceptions(allow_exceptions_)
{ {
// read first token // read first token
get_token(); get_token();

View file

@ -196,10 +196,12 @@ class basic_json
static ::nlohmann::detail::parser<basic_json, InputAdapterType> parser( static ::nlohmann::detail::parser<basic_json, InputAdapterType> parser(
InputAdapterType adapter, InputAdapterType adapter,
detail::parser_callback_t<basic_json>cb = nullptr, detail::parser_callback_t<basic_json>cb = nullptr,
bool allow_exceptions = true const bool allow_exceptions = true,
const bool ignore_comments = false
) )
{ {
return ::nlohmann::detail::parser<basic_json, InputAdapterType>(std::move(adapter), std::move(cb), allow_exceptions); return ::nlohmann::detail::parser<basic_json, InputAdapterType>(std::move(adapter),
std::move(cb), allow_exceptions, ignore_comments);
} }
using primitive_iterator_t = ::nlohmann::detail::primitive_iterator_t; using primitive_iterator_t = ::nlohmann::detail::primitive_iterator_t;
@ -6563,6 +6565,8 @@ class basic_json
(optional) (optional)
@param[in] allow_exceptions whether to throw exceptions in case of a @param[in] allow_exceptions whether to throw exceptions in case of a
parse error (optional, true by default) parse error (optional, true by default)
@param[in] ignore_comments whether comments should be ignored (true) or
yield a parse error (true); (optional, false by default)
@return deserialized JSON value; in case of a parse error and @return deserialized JSON value; in case of a parse error and
@a allow_exceptions set to `false`, the return value will be @a allow_exceptions set to `false`, the return value will be
@ -6591,16 +6595,18 @@ class basic_json
@liveexample{The example below demonstrates the `parse()` function reading @liveexample{The example below demonstrates the `parse()` function reading
from a contiguous container.,parse__contiguouscontainer__parser_callback_t} from a contiguous container.,parse__contiguouscontainer__parser_callback_t}
@since version 2.0.3 (contiguous containers) @since version 2.0.3 (contiguous containers); version 3.9.0 allowed to
ignore comments.
*/ */
template<typename InputType> template<typename InputType>
JSON_HEDLEY_WARN_UNUSED_RESULT JSON_HEDLEY_WARN_UNUSED_RESULT
static basic_json parse(InputType&& i, static basic_json parse(InputType&& i,
const parser_callback_t cb = nullptr, const parser_callback_t cb = nullptr,
const bool allow_exceptions = true) const bool allow_exceptions = true,
const bool ignore_comments = false)
{ {
basic_json result; basic_json result;
parser(detail::input_adapter(std::forward<InputType>(i)), cb, allow_exceptions).parse(true, result); parser(detail::input_adapter(std::forward<InputType>(i)), cb, allow_exceptions, ignore_comments).parse(true, result);
return result; return result;
} }
@ -6617,6 +6623,8 @@ class basic_json
(optional) (optional)
@param[in] allow_exceptions whether to throw exceptions in case of a @param[in] allow_exceptions whether to throw exceptions in case of a
parse error (optional, true by default) parse error (optional, true by default)
@param[in] ignore_comments whether comments should be ignored (true) or
yield a parse error (true); (optional, false by default)
@return deserialized JSON value; in case of a parse error and @return deserialized JSON value; in case of a parse error and
@a allow_exceptions set to `false`, the return value will be @a allow_exceptions set to `false`, the return value will be
@ -6632,10 +6640,11 @@ class basic_json
static basic_json parse(IteratorType first, static basic_json parse(IteratorType first,
IteratorType last, IteratorType last,
const parser_callback_t cb = nullptr, const parser_callback_t cb = nullptr,
const bool allow_exceptions = true) const bool allow_exceptions = true,
const bool ignore_comments = false)
{ {
basic_json result; basic_json result;
parser(detail::input_adapter(std::move(first), std::move(last)), cb, allow_exceptions).parse(true, result); parser(detail::input_adapter(std::move(first), std::move(last)), cb, allow_exceptions, ignore_comments).parse(true, result);
return result; return result;
} }
@ -6643,10 +6652,11 @@ class basic_json
JSON_HEDLEY_DEPRECATED_FOR(3.8.0, parse(ptr, ptr + len)) JSON_HEDLEY_DEPRECATED_FOR(3.8.0, parse(ptr, ptr + len))
static basic_json parse(detail::span_input_adapter&& i, static basic_json parse(detail::span_input_adapter&& i,
const parser_callback_t cb = nullptr, const parser_callback_t cb = nullptr,
const bool allow_exceptions = true) const bool allow_exceptions = true,
const bool ignore_comments = false)
{ {
basic_json result; basic_json result;
parser(i.get(), cb, allow_exceptions).parse(true, result); parser(i.get(), cb, allow_exceptions, ignore_comments).parse(true, result);
return result; return result;
} }
@ -6666,6 +6676,8 @@ class basic_json
iterators. iterators.
@param[in] i input to read from @param[in] i input to read from
@param[in] ignore_comments whether comments should be ignored (true) or
yield a parse error (true); (optional, false by default)
@return Whether the input read from @a i is valid JSON. @return Whether the input read from @a i is valid JSON.
@ -6678,22 +6690,25 @@ class basic_json
from a string.,accept__string} from a string.,accept__string}
*/ */
template<typename InputType> template<typename InputType>
static bool accept(InputType&& i) static bool accept(InputType&& i,
const bool ignore_comments = false)
{ {
return parser(detail::input_adapter(std::forward<InputType>(i))).accept(true); return parser(detail::input_adapter(std::forward<InputType>(i)), nullptr, false, ignore_comments).accept(true);
} }
template<typename IteratorType> template<typename IteratorType>
static bool accept(IteratorType first, IteratorType last) static bool accept(IteratorType first, IteratorType last,
const bool ignore_comments = false)
{ {
return parser(detail::input_adapter(std::move(first), std::move(last))).accept(true); return parser(detail::input_adapter(std::move(first), std::move(last)), nullptr, false, ignore_comments).accept(true);
} }
JSON_HEDLEY_WARN_UNUSED_RESULT JSON_HEDLEY_WARN_UNUSED_RESULT
JSON_HEDLEY_DEPRECATED_FOR(3.8.0, accept(ptr, ptr + len)) JSON_HEDLEY_DEPRECATED_FOR(3.8.0, accept(ptr, ptr + len))
static bool accept(detail::span_input_adapter&& i) static bool accept(detail::span_input_adapter&& i,
const bool ignore_comments = false)
{ {
return parser(i.get()).accept(true); return parser(i.get(), nullptr, false, ignore_comments).accept(true);
} }
/*! /*!
@ -6713,6 +6728,9 @@ class basic_json
@param[in,out] sax SAX event listener @param[in,out] sax SAX event listener
@param[in] format the format to parse (JSON, CBOR, MessagePack, or UBJSON) @param[in] format the format to parse (JSON, CBOR, MessagePack, or UBJSON)
@param[in] strict whether the input has to be consumed completely @param[in] strict whether the input has to be consumed completely
@param[in] ignore_comments whether comments should be ignored (true) or
yield a parse error (true); (optional, false by default); only applieds to
the JSON file format.
@return return value of the last processed SAX event @return return value of the last processed SAX event
@ -6737,11 +6755,12 @@ class basic_json
JSON_HEDLEY_NON_NULL(2) JSON_HEDLEY_NON_NULL(2)
static bool sax_parse(InputType&& i, SAX* sax, static bool sax_parse(InputType&& i, SAX* sax,
input_format_t format = input_format_t::json, input_format_t format = input_format_t::json,
const bool strict = true) const bool strict = true,
const bool ignore_comments = false)
{ {
auto ia = detail::input_adapter(std::forward<InputType>(i)); auto ia = detail::input_adapter(std::forward<InputType>(i));
return format == input_format_t::json return format == input_format_t::json
? parser(std::move(ia)).sax_parse(sax, strict) ? parser(std::move(ia), nullptr, true, ignore_comments).sax_parse(sax, strict)
: detail::binary_reader<basic_json, decltype(ia), SAX>(std::move(ia)).sax_parse(format, sax, strict); : detail::binary_reader<basic_json, decltype(ia), SAX>(std::move(ia)).sax_parse(format, sax, strict);
} }
@ -6749,11 +6768,12 @@ class basic_json
JSON_HEDLEY_NON_NULL(3) JSON_HEDLEY_NON_NULL(3)
static bool sax_parse(IteratorType first, IteratorType last, SAX* sax, static bool sax_parse(IteratorType first, IteratorType last, SAX* sax,
input_format_t format = input_format_t::json, input_format_t format = input_format_t::json,
const bool strict = true) const bool strict = true,
const bool ignore_comments = false)
{ {
auto ia = detail::input_adapter(std::move(first), std::move(last)); auto ia = detail::input_adapter(std::move(first), std::move(last));
return format == input_format_t::json return format == input_format_t::json
? parser(std::move(ia)).sax_parse(sax, strict) ? parser(std::move(ia), nullptr, true, ignore_comments).sax_parse(sax, strict)
: detail::binary_reader<basic_json, decltype(ia), SAX>(std::move(ia)).sax_parse(format, sax, strict); : detail::binary_reader<basic_json, decltype(ia), SAX>(std::move(ia)).sax_parse(format, sax, strict);
} }
@ -6762,11 +6782,12 @@ class basic_json
JSON_HEDLEY_NON_NULL(2) JSON_HEDLEY_NON_NULL(2)
static bool sax_parse(detail::span_input_adapter&& i, SAX* sax, static bool sax_parse(detail::span_input_adapter&& i, SAX* sax,
input_format_t format = input_format_t::json, input_format_t format = input_format_t::json,
const bool strict = true) const bool strict = true,
const bool ignore_comments = false)
{ {
auto ia = i.get(); auto ia = i.get();
return format == input_format_t::json return format == input_format_t::json
? parser(std::move(ia)).sax_parse(sax, strict) ? parser(std::move(ia), nullptr, true, ignore_comments).sax_parse(sax, strict)
: detail::binary_reader<basic_json, decltype(ia), SAX>(std::move(ia)).sax_parse(format, sax, strict); : detail::binary_reader<basic_json, decltype(ia), SAX>(std::move(ia)).sax_parse(format, sax, strict);
} }

View file

@ -8904,6 +8904,7 @@ class lexer : public lexer_base<BasicJsonType>
{ {
switch (get()) switch (get())
{ {
// single-line comments skip input until a newline or EOF is read
case '/': case '/':
{ {
while (true) while (true)
@ -8912,6 +8913,8 @@ class lexer : public lexer_base<BasicJsonType>
{ {
case '\n': case '\n':
case '\r': case '\r':
case std::char_traits<char_type>::eof():
case '\0':
return true; return true;
default: default:
@ -8920,6 +8923,7 @@ class lexer : public lexer_base<BasicJsonType>
} }
} }
// multi-line comments skip input until */ is read
case '*': case '*':
{ {
while (true) while (true)
@ -8944,10 +8948,14 @@ class lexer : public lexer_base<BasicJsonType>
} }
} }
} }
default:
break;
} }
} }
} }
// unexpected character after reading '/'
default: default:
return false; return false;
} }
@ -9742,8 +9750,11 @@ class parser
/// a parser reading from an input adapter /// a parser reading from an input adapter
explicit parser(InputAdapterType&& adapter, explicit parser(InputAdapterType&& adapter,
const parser_callback_t<BasicJsonType> cb = nullptr, const parser_callback_t<BasicJsonType> cb = nullptr,
const bool allow_exceptions_ = true) const bool allow_exceptions_ = true,
: callback(cb), m_lexer(std::move(adapter)), allow_exceptions(allow_exceptions_) const bool skip_comments = false)
: callback(cb)
, m_lexer(std::move(adapter), skip_comments)
, allow_exceptions(allow_exceptions_)
{ {
// read first token // read first token
get_token(); get_token();
@ -16051,10 +16062,12 @@ class basic_json
static ::nlohmann::detail::parser<basic_json, InputAdapterType> parser( static ::nlohmann::detail::parser<basic_json, InputAdapterType> parser(
InputAdapterType adapter, InputAdapterType adapter,
detail::parser_callback_t<basic_json>cb = nullptr, detail::parser_callback_t<basic_json>cb = nullptr,
bool allow_exceptions = true const bool allow_exceptions = true,
const bool ignore_comments = false
) )
{ {
return ::nlohmann::detail::parser<basic_json, InputAdapterType>(std::move(adapter), std::move(cb), allow_exceptions); return ::nlohmann::detail::parser<basic_json, InputAdapterType>(std::move(adapter),
std::move(cb), allow_exceptions, ignore_comments);
} }
using primitive_iterator_t = ::nlohmann::detail::primitive_iterator_t; using primitive_iterator_t = ::nlohmann::detail::primitive_iterator_t;
@ -22418,6 +22431,8 @@ class basic_json
(optional) (optional)
@param[in] allow_exceptions whether to throw exceptions in case of a @param[in] allow_exceptions whether to throw exceptions in case of a
parse error (optional, true by default) parse error (optional, true by default)
@param[in] ignore_comments whether comments should be ignored (true) or
yield a parse error (true); (optional, false by default)
@return deserialized JSON value; in case of a parse error and @return deserialized JSON value; in case of a parse error and
@a allow_exceptions set to `false`, the return value will be @a allow_exceptions set to `false`, the return value will be
@ -22446,16 +22461,18 @@ class basic_json
@liveexample{The example below demonstrates the `parse()` function reading @liveexample{The example below demonstrates the `parse()` function reading
from a contiguous container.,parse__contiguouscontainer__parser_callback_t} from a contiguous container.,parse__contiguouscontainer__parser_callback_t}
@since version 2.0.3 (contiguous containers) @since version 2.0.3 (contiguous containers); version 3.9.0 allowed to
ignore comments.
*/ */
template<typename InputType> template<typename InputType>
JSON_HEDLEY_WARN_UNUSED_RESULT JSON_HEDLEY_WARN_UNUSED_RESULT
static basic_json parse(InputType&& i, static basic_json parse(InputType&& i,
const parser_callback_t cb = nullptr, const parser_callback_t cb = nullptr,
const bool allow_exceptions = true) const bool allow_exceptions = true,
const bool ignore_comments = false)
{ {
basic_json result; basic_json result;
parser(detail::input_adapter(std::forward<InputType>(i)), cb, allow_exceptions).parse(true, result); parser(detail::input_adapter(std::forward<InputType>(i)), cb, allow_exceptions, ignore_comments).parse(true, result);
return result; return result;
} }
@ -22472,6 +22489,8 @@ class basic_json
(optional) (optional)
@param[in] allow_exceptions whether to throw exceptions in case of a @param[in] allow_exceptions whether to throw exceptions in case of a
parse error (optional, true by default) parse error (optional, true by default)
@param[in] ignore_comments whether comments should be ignored (true) or
yield a parse error (true); (optional, false by default)
@return deserialized JSON value; in case of a parse error and @return deserialized JSON value; in case of a parse error and
@a allow_exceptions set to `false`, the return value will be @a allow_exceptions set to `false`, the return value will be
@ -22487,10 +22506,11 @@ class basic_json
static basic_json parse(IteratorType first, static basic_json parse(IteratorType first,
IteratorType last, IteratorType last,
const parser_callback_t cb = nullptr, const parser_callback_t cb = nullptr,
const bool allow_exceptions = true) const bool allow_exceptions = true,
const bool ignore_comments = false)
{ {
basic_json result; basic_json result;
parser(detail::input_adapter(std::move(first), std::move(last)), cb, allow_exceptions).parse(true, result); parser(detail::input_adapter(std::move(first), std::move(last)), cb, allow_exceptions, ignore_comments).parse(true, result);
return result; return result;
} }
@ -22498,10 +22518,11 @@ class basic_json
JSON_HEDLEY_DEPRECATED_FOR(3.8.0, parse(ptr, ptr + len)) JSON_HEDLEY_DEPRECATED_FOR(3.8.0, parse(ptr, ptr + len))
static basic_json parse(detail::span_input_adapter&& i, static basic_json parse(detail::span_input_adapter&& i,
const parser_callback_t cb = nullptr, const parser_callback_t cb = nullptr,
const bool allow_exceptions = true) const bool allow_exceptions = true,
const bool ignore_comments = false)
{ {
basic_json result; basic_json result;
parser(i.get(), cb, allow_exceptions).parse(true, result); parser(i.get(), cb, allow_exceptions, ignore_comments).parse(true, result);
return result; return result;
} }
@ -22521,6 +22542,8 @@ class basic_json
iterators. iterators.
@param[in] i input to read from @param[in] i input to read from
@param[in] ignore_comments whether comments should be ignored (true) or
yield a parse error (true); (optional, false by default)
@return Whether the input read from @a i is valid JSON. @return Whether the input read from @a i is valid JSON.
@ -22533,22 +22556,25 @@ class basic_json
from a string.,accept__string} from a string.,accept__string}
*/ */
template<typename InputType> template<typename InputType>
static bool accept(InputType&& i) static bool accept(InputType&& i,
const bool ignore_comments = false)
{ {
return parser(detail::input_adapter(std::forward<InputType>(i))).accept(true); return parser(detail::input_adapter(std::forward<InputType>(i)), nullptr, false, ignore_comments).accept(true);
} }
template<typename IteratorType> template<typename IteratorType>
static bool accept(IteratorType first, IteratorType last) static bool accept(IteratorType first, IteratorType last,
const bool ignore_comments = false)
{ {
return parser(detail::input_adapter(std::move(first), std::move(last))).accept(true); return parser(detail::input_adapter(std::move(first), std::move(last)), nullptr, false, ignore_comments).accept(true);
} }
JSON_HEDLEY_WARN_UNUSED_RESULT JSON_HEDLEY_WARN_UNUSED_RESULT
JSON_HEDLEY_DEPRECATED_FOR(3.8.0, accept(ptr, ptr + len)) JSON_HEDLEY_DEPRECATED_FOR(3.8.0, accept(ptr, ptr + len))
static bool accept(detail::span_input_adapter&& i) static bool accept(detail::span_input_adapter&& i,
const bool ignore_comments = false)
{ {
return parser(i.get()).accept(true); return parser(i.get(), nullptr, false, ignore_comments).accept(true);
} }
/*! /*!
@ -22568,6 +22594,9 @@ class basic_json
@param[in,out] sax SAX event listener @param[in,out] sax SAX event listener
@param[in] format the format to parse (JSON, CBOR, MessagePack, or UBJSON) @param[in] format the format to parse (JSON, CBOR, MessagePack, or UBJSON)
@param[in] strict whether the input has to be consumed completely @param[in] strict whether the input has to be consumed completely
@param[in] ignore_comments whether comments should be ignored (true) or
yield a parse error (true); (optional, false by default); only applieds to
the JSON file format.
@return return value of the last processed SAX event @return return value of the last processed SAX event
@ -22592,11 +22621,12 @@ class basic_json
JSON_HEDLEY_NON_NULL(2) JSON_HEDLEY_NON_NULL(2)
static bool sax_parse(InputType&& i, SAX* sax, static bool sax_parse(InputType&& i, SAX* sax,
input_format_t format = input_format_t::json, input_format_t format = input_format_t::json,
const bool strict = true) const bool strict = true,
const bool ignore_comments = false)
{ {
auto ia = detail::input_adapter(std::forward<InputType>(i)); auto ia = detail::input_adapter(std::forward<InputType>(i));
return format == input_format_t::json return format == input_format_t::json
? parser(std::move(ia)).sax_parse(sax, strict) ? parser(std::move(ia), nullptr, true, ignore_comments).sax_parse(sax, strict)
: detail::binary_reader<basic_json, decltype(ia), SAX>(std::move(ia)).sax_parse(format, sax, strict); : detail::binary_reader<basic_json, decltype(ia), SAX>(std::move(ia)).sax_parse(format, sax, strict);
} }
@ -22604,11 +22634,12 @@ class basic_json
JSON_HEDLEY_NON_NULL(3) JSON_HEDLEY_NON_NULL(3)
static bool sax_parse(IteratorType first, IteratorType last, SAX* sax, static bool sax_parse(IteratorType first, IteratorType last, SAX* sax,
input_format_t format = input_format_t::json, input_format_t format = input_format_t::json,
const bool strict = true) const bool strict = true,
const bool ignore_comments = false)
{ {
auto ia = detail::input_adapter(std::move(first), std::move(last)); auto ia = detail::input_adapter(std::move(first), std::move(last));
return format == input_format_t::json return format == input_format_t::json
? parser(std::move(ia)).sax_parse(sax, strict) ? parser(std::move(ia), nullptr, true, ignore_comments).sax_parse(sax, strict)
: detail::binary_reader<basic_json, decltype(ia), SAX>(std::move(ia)).sax_parse(format, sax, strict); : detail::binary_reader<basic_json, decltype(ia), SAX>(std::move(ia)).sax_parse(format, sax, strict);
} }
@ -22617,11 +22648,12 @@ class basic_json
JSON_HEDLEY_NON_NULL(2) JSON_HEDLEY_NON_NULL(2)
static bool sax_parse(detail::span_input_adapter&& i, SAX* sax, static bool sax_parse(detail::span_input_adapter&& i, SAX* sax,
input_format_t format = input_format_t::json, input_format_t format = input_format_t::json,
const bool strict = true) const bool strict = true,
const bool ignore_comments = false)
{ {
auto ia = i.get(); auto ia = i.get();
return format == input_format_t::json return format == input_format_t::json
? parser(std::move(ia)).sax_parse(sax, strict) ? parser(std::move(ia), nullptr, true, ignore_comments).sax_parse(sax, strict)
: detail::binary_reader<basic_json, decltype(ia), SAX>(std::move(ia)).sax_parse(format, sax, strict); : detail::binary_reader<basic_json, decltype(ia), SAX>(std::move(ia)).sax_parse(format, sax, strict);
} }

View file

@ -37,11 +37,11 @@ using nlohmann::json;
namespace namespace
{ {
// shortcut to scan a string literal // shortcut to scan a string literal
json::lexer::token_type scan_string(const char* s); json::lexer::token_type scan_string(const char* s, const bool ignore_comments = false);
json::lexer::token_type scan_string(const char* s) json::lexer::token_type scan_string(const char* s, const bool ignore_comments)
{ {
auto ia = nlohmann::detail::input_adapter(s); auto ia = nlohmann::detail::input_adapter(s);
return nlohmann::detail::lexer<json, decltype(ia)>(std::move(ia)).scan(); return nlohmann::detail::lexer<json, decltype(ia)>(std::move(ia), ignore_comments).scan();
} }
} }
@ -163,9 +163,6 @@ TEST_CASE("lexer class")
break; break;
} }
// case ('/'):
// break;
// anything else is not expected // anything else is not expected
default: default:
{ {
@ -185,18 +182,39 @@ TEST_CASE("lexer class")
CHECK((scan_string(s.c_str()) == json::lexer::token_type::value_string)); CHECK((scan_string(s.c_str()) == json::lexer::token_type::value_string));
} }
// SECTION("ignore comments") SECTION("fail on comments")
// { {
// CHECK((scan_string("/") == json::lexer::token_type::parse_error)); CHECK((scan_string("/", false) == json::lexer::token_type::parse_error));
//
// CHECK((scan_string("/!") == json::lexer::token_type::parse_error)); CHECK((scan_string("/!", false) == json::lexer::token_type::parse_error));
// CHECK((scan_string("/*") == json::lexer::token_type::parse_error)); CHECK((scan_string("/*", false) == json::lexer::token_type::parse_error));
// CHECK((scan_string("/**") == json::lexer::token_type::parse_error)); CHECK((scan_string("/**", false) == json::lexer::token_type::parse_error));
//
// CHECK((scan_string("//") == json::lexer::token_type::end_of_input)); CHECK((scan_string("//", false) == json::lexer::token_type::parse_error));
// CHECK((scan_string("/**/") == json::lexer::token_type::end_of_input)); CHECK((scan_string("/**/", false) == json::lexer::token_type::parse_error));
// CHECK((scan_string("/** /") == json::lexer::token_type::parse_error)); CHECK((scan_string("/** /", false) == json::lexer::token_type::parse_error));
//
// CHECK((scan_string("/***/") == json::lexer::token_type::end_of_input)); CHECK((scan_string("/***/", false) == json::lexer::token_type::parse_error));
// } CHECK((scan_string("/* true */", false) == json::lexer::token_type::parse_error));
CHECK((scan_string("/*/**/", false) == json::lexer::token_type::parse_error));
CHECK((scan_string("/*/* */", false) == json::lexer::token_type::parse_error));
}
SECTION("ignore comments")
{
CHECK((scan_string("/", true) == json::lexer::token_type::parse_error));
CHECK((scan_string("/!", true) == json::lexer::token_type::parse_error));
CHECK((scan_string("/*", true) == json::lexer::token_type::parse_error));
CHECK((scan_string("/**", true) == json::lexer::token_type::parse_error));
CHECK((scan_string("//", true) == json::lexer::token_type::end_of_input));
CHECK((scan_string("/**/", true) == json::lexer::token_type::end_of_input));
CHECK((scan_string("/** /", true) == json::lexer::token_type::parse_error));
CHECK((scan_string("/***/", true) == json::lexer::token_type::end_of_input));
CHECK((scan_string("/* true */", true) == json::lexer::token_type::end_of_input));
CHECK((scan_string("/*/**/", true) == json::lexer::token_type::end_of_input));
CHECK((scan_string("/*/* */", true) == json::lexer::token_type::end_of_input));
}
} }