Skip to content

Commit

Permalink
Allow nested block comments, fixes #774
Browse files Browse the repository at this point in the history
  • Loading branch information
nickbattle committed Feb 5, 2021
1 parent 7bced1c commit 100d48d
Showing 1 changed file with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -929,10 +929,11 @@ else if (ch == '>')
StringBuilder sb = new StringBuilder();
rdCh();
ILexLocation here = location(linecount, charpos, tokline, tokpos);
int nestedCount = 0;

while (ch != EOF)
{
while (ch != '*' && ch != EOF)
while (ch != '*' && ch != '/' && ch != EOF)
{
sb.append(ch);
rdCh();
Expand All @@ -942,11 +943,32 @@ else if (ch == '>')
{
throwMessage(1011, tokline, tokpos, "Unterminated block comment");
}
else if (ch == '/')
{
sb.append('/');

if (rdCh() == '*')
{
nestedCount++;
sb.append('*');
rdCh();
}
}
else
{
if (rdCh() == '/')
{
break;
if (nestedCount == 0)
{
break;
}
else
{
nestedCount--;
sb.append('*');
sb.append('/');
rdCh();
}
}
else
{
Expand Down

0 comments on commit 100d48d

Please sign in to comment.