improve comment parsing

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