improve comment parsing

parent b53c6e2f
......@@ -835,62 +835,54 @@ 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 != '*')
{
return false;
}
while (true)
switch (get())
{
switch (get())
case '/':
{
// EOF inside a /* comment is an error, in // it is OK
case std::char_traits<char_type>::eof():
case '\0':
while (true)
{
return comment_char == '/';
}
// a newline ends the // comment
case '\n':
case '\r':
{
if (comment_char == '/')
switch (get())
{
return true;
case '\n':
case '\r':
return true;
default:
break;
}
break;
}
}
// */ ends the /* comment
case '*':
case '*':
{
while (true)
{
if (comment_char == '*')
switch (get())
{
switch (get())
case std::char_traits<char_type>::eof():
case '\0':
return false;
case '*':
{
case '/':
switch (get())
{
return true;
}
case '/':
return true;
default:
{
unget();
break;
default:
{
unget();
break;
}
}
}
}
break;
}
default:
break;
}
default:
return false;
}
}
......
......@@ -8902,62 +8902,54 @@ 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 != '*')
{
return false;
}
while (true)
switch (get())
{
switch (get())
case '/':
{
// EOF inside a /* comment is an error, in // it is OK
case std::char_traits<char_type>::eof():
case '\0':
while (true)
{
return comment_char == '/';
}
// a newline ends the // comment
case '\n':
case '\r':
{
if (comment_char == '/')
switch (get())
{
return true;
case '\n':
case '\r':
return true;
default:
break;
}
break;
}
}
// */ ends the /* comment
case '*':
case '*':
{
while (true)
{
if (comment_char == '*')
switch (get())
{
switch (get())
case std::char_traits<char_type>::eof():
case '\0':
return false;
case '*':
{
case '/':
switch (get())
{
return true;
}
case '/':
return true;
default:
{
unget();
break;
default:
{
unget();
break;
}
}
}
}
break;
}
default:
break;
}
default:
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