improve comment parsing

parent b53c6e2f
......@@ -835,48 +835,40 @@ class lexer : public lexer_base<BasicJsonType>
*/
bool scan_comment()
{
// remember character after '/' to distinguish comment types
const auto comment_char = get();
// expect // or /* to start a comment
if (comment_char != '/' and comment_char != '*')
switch (get())
{
case '/':
{
return false;
}
while (true)
{
switch (get())
{
// EOF inside a /* comment is an error, in // it is OK
case std::char_traits<char_type>::eof():
case '\0':
{
return comment_char == '/';
}
// a newline ends the // comment
case '\n':
case '\r':
{
if (comment_char == '/')
{
return true;
}
default:
break;
}
}
}
// */ ends the /* comment
case '*':
{
if (comment_char == '*')
while (true)
{
switch (get())
{
case '/':
case std::char_traits<char_type>::eof():
case '\0':
return false;
case '*':
{
switch (get())
{
case '/':
return true;
}
default:
{
......@@ -885,12 +877,12 @@ class lexer : public lexer_base<BasicJsonType>
}
}
}
break;
}
}
}
default:
break;
}
return false;
}
}
......
......@@ -8902,48 +8902,40 @@ class lexer : public lexer_base<BasicJsonType>
*/
bool scan_comment()
{
// remember character after '/' to distinguish comment types
const auto comment_char = get();
// expect // or /* to start a comment
if (comment_char != '/' and comment_char != '*')
switch (get())
{
case '/':
{
return false;
}
while (true)
{
switch (get())
{
// EOF inside a /* comment is an error, in // it is OK
case std::char_traits<char_type>::eof():
case '\0':
{
return comment_char == '/';
}
// a newline ends the // comment
case '\n':
case '\r':
{
if (comment_char == '/')
{
return true;
}
default:
break;
}
}
}
// */ ends the /* comment
case '*':
{
if (comment_char == '*')
while (true)
{
switch (get())
{
case '/':
case std::char_traits<char_type>::eof():
case '\0':
return false;
case '*':
{
switch (get())
{
case '/':
return true;
}
default:
{
......@@ -8952,12 +8944,12 @@ class lexer : public lexer_base<BasicJsonType>
}
}
}
break;
}
}
}
default:
break;
}
return false;
}
}
......
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