Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix (or just change?) how we report comments vs newlines.
Multi-line comments now swallow internal newlines and don't insert a fake one
in the token stream, so this works like GNU cpp now:

    #if /*
    */1
    This should be included by the preprocessor, believe it or not.
    #endif

Single-line comments no longer swallow their terminating endline, which makes
this case work:

    #if BLAH  // The preprocessor expects a newline token here.
    #endif
  • Loading branch information
icculus committed Feb 15, 2013
1 parent 2dcd52d commit 0ca0465
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
8 changes: 3 additions & 5 deletions mojoshader_lexer.c
Expand Up @@ -65,7 +65,6 @@ Token preprocessor_lexer(IncludeState *s)
const uchar *matchptr;
const uchar *limit = cursor + s->bytes_left;
int eoi = 0;
int saw_newline = 0;



Expand Down Expand Up @@ -1139,8 +1138,6 @@ Token preprocessor_lexer(IncludeState *s)
yy186:
{
s->line++;
token = matchptr;
saw_newline = 1;
goto multilinecomment;
}
yy187:
Expand All @@ -1165,8 +1162,6 @@ Token preprocessor_lexer(IncludeState *s)
{
if (s->report_comments)
RET(TOKEN_MULTI_COMMENT);
else if (saw_newline)
RET('\n');
else if (s->report_whitespace)
RET(' ');
goto scanner_loop;
Expand Down Expand Up @@ -1194,7 +1189,10 @@ Token preprocessor_lexer(IncludeState *s)
{
s->line++;
if (s->report_comments)
{
cursor = matchptr; // so we RET('\n') next.
RET(TOKEN_SINGLE_COMMENT);
}
token = matchptr;
RET('\n');
}
Expand Down
8 changes: 3 additions & 5 deletions mojoshader_lexer.re
Expand Up @@ -64,7 +64,6 @@ Token preprocessor_lexer(IncludeState *s)
const uchar *matchptr;
const uchar *limit = cursor + s->bytes_left;
int eoi = 0;
int saw_newline = 0;

/*!re2c
ANY = [\000-\377];
Expand Down Expand Up @@ -171,16 +170,12 @@ multilinecomment:
"*\/" {
if (s->report_comments)
RET(TOKEN_MULTI_COMMENT);
else if (saw_newline)
RET('\n');
else if (s->report_whitespace)
RET(' ');
goto scanner_loop;
}
NEWLINE {
s->line++;
token = matchptr;
saw_newline = 1;
goto multilinecomment;
}
"\000" {
Expand All @@ -198,7 +193,10 @@ singlelinecomment:
NEWLINE {
s->line++;
if (s->report_comments)
{
cursor = matchptr; // so we RET('\n') next.
RET(TOKEN_SINGLE_COMMENT);
}
token = matchptr;
RET('\n');
}
Expand Down

0 comments on commit 0ca0465

Please sign in to comment.