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

View file

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