Skip to content
Permalink
Browse files
Reworked preprocessor newline management.
My thought about the semicolon and assembly comments was a brain fart,
 newlines will have to go through to the assembler, and we'll just mirror
 Direct3D's preprocessor output behaviour in MOJOSHADER_preprocess() instead.

This gets rid of the nasty insert_token nonsense, as an added benefit.
  • Loading branch information
icculus committed Feb 12, 2009
1 parent 7f70e9a commit 67966432d48c3e905be9d6e72d7e9e53a16b4557

File 2 of 3 in 6796643

@@ -24,7 +24,7 @@

typedef unsigned char uchar;

#define RET(t) { update_state(s, cursor, token); return t; }
#define RET(t) do { update_state(s, cursor, token); return t; } while (0)
#define YYCTYPE uchar
#define YYCURSOR cursor
#define YYLIMIT limit
@@ -43,6 +43,7 @@ Token preprocessor_internal_lexer(IncludeState *s)
const uchar *cursor = (const uchar *) s->source;
const uchar *token;
const uchar *limit = cursor + s->bytes_left;
int saw_newline = 0;

scanner_loop:
token = cursor;
@@ -131,7 +132,7 @@ scanner_loop:
PP "error" { RET(TOKEN_PP_ERROR); }
WHITESPACE { goto scanner_loop; }
NEWLINE { s->line++; goto scanner_loop; }
NEWLINE { s->line++; RET('\n'); }
any { printf("bad char\n"); goto scanner_loop; }
*/

@@ -140,16 +141,25 @@ multilinecomment:
RET(TOKEN_PP_INCOMPLETE_COMMENT);
// The "*\/" is just to avoid screwing up text editor syntax highlighting.
/*!re2c
"*\/" { goto scanner_loop; }
NEWLINE { s->line++; goto multilinecomment; }
"*\/" {
if (saw_newline)
RET('\n');
goto scanner_loop;
}
NEWLINE {
s->line++;
token = cursor-1;
saw_newline = 1;
goto multilinecomment;
}
any { goto multilinecomment; }
*/

singlelinecomment:
if (YYLIMIT == YYCURSOR)
RET(TOKEN_EOI);
/*!re2c
NEWLINE { s->line++; goto scanner_loop; }
NEWLINE { s->line++; token = cursor-1; RET('\n'); }
any { goto singlelinecomment; }
*/

0 comments on commit 6796643

Please sign in to comment.