mojoshader_lexer.re
changeset 564 c669568326fb
parent 555 940821555fda
child 584 9aea8877564d
equal deleted inserted replaced
563:d22551643fcb 564:c669568326fb
    22 #define __MOJOSHADER_INTERNAL__ 1
    22 #define __MOJOSHADER_INTERNAL__ 1
    23 #include "mojoshader_internal.h"
    23 #include "mojoshader_internal.h"
    24 
    24 
    25 typedef unsigned char uchar;
    25 typedef unsigned char uchar;
    26 
    26 
    27 #define RET(t) { update_state(s, cursor, token); return t; }
    27 #define RET(t) do { update_state(s, cursor, token); return t; } while (0)
    28 #define YYCTYPE uchar
    28 #define YYCTYPE uchar
    29 #define YYCURSOR cursor
    29 #define YYCURSOR cursor
    30 #define YYLIMIT limit
    30 #define YYLIMIT limit
    31 #define YYMARKER s->lexer_marker
    31 #define YYMARKER s->lexer_marker
    32 #define YYFILL(n) { if ((n) == 1) { RET(TOKEN_EOI); } }
    32 #define YYFILL(n) { if ((n) == 1) { RET(TOKEN_EOI); } }
    41 Token preprocessor_internal_lexer(IncludeState *s)
    41 Token preprocessor_internal_lexer(IncludeState *s)
    42 {
    42 {
    43     const uchar *cursor = (const uchar *) s->source;
    43     const uchar *cursor = (const uchar *) s->source;
    44     const uchar *token;
    44     const uchar *token;
    45     const uchar *limit = cursor + s->bytes_left;
    45     const uchar *limit = cursor + s->bytes_left;
       
    46     int saw_newline = 0;
    46 
    47 
    47 scanner_loop:
    48 scanner_loop:
    48     token = cursor;
    49     token = cursor;
    49 
    50 
    50     if (YYLIMIT == YYCURSOR)
    51     if (YYLIMIT == YYCURSOR)
   129     PP "elif"       { RET(TOKEN_PP_ELIF); }
   130     PP "elif"       { RET(TOKEN_PP_ELIF); }
   130     PP "endif"      { RET(TOKEN_PP_ENDIF); }
   131     PP "endif"      { RET(TOKEN_PP_ENDIF); }
   131     PP "error"      { RET(TOKEN_PP_ERROR); }
   132     PP "error"      { RET(TOKEN_PP_ERROR); }
   132 
   133 
   133     WHITESPACE      { goto scanner_loop; }
   134     WHITESPACE      { goto scanner_loop; }
   134     NEWLINE         { s->line++; goto scanner_loop; }
   135     NEWLINE         { s->line++; RET('\n'); }
   135     any             { printf("bad char\n"); goto scanner_loop; }
   136     any             { printf("bad char\n"); goto scanner_loop; }
   136 */
   137 */
   137 
   138 
   138 multilinecomment:
   139 multilinecomment:
   139     if (YYLIMIT == YYCURSOR)
   140     if (YYLIMIT == YYCURSOR)
   140         RET(TOKEN_PP_INCOMPLETE_COMMENT);
   141         RET(TOKEN_PP_INCOMPLETE_COMMENT);
   141 // The "*\/" is just to avoid screwing up text editor syntax highlighting.
   142 // The "*\/" is just to avoid screwing up text editor syntax highlighting.
   142 /*!re2c
   143 /*!re2c
   143     "*\/"           { goto scanner_loop; }
   144     "*\/"           {
   144     NEWLINE         { s->line++; goto multilinecomment; }
   145                         if (saw_newline)
       
   146                             RET('\n');
       
   147                         goto scanner_loop;
       
   148                     }
       
   149     NEWLINE         {
       
   150                         s->line++;
       
   151                         token = cursor-1;
       
   152                         saw_newline = 1;
       
   153                         goto multilinecomment;
       
   154                     }
   145     any             { goto multilinecomment; }
   155     any             { goto multilinecomment; }
   146 */
   156 */
   147 
   157 
   148 singlelinecomment:
   158 singlelinecomment:
   149     if (YYLIMIT == YYCURSOR)
   159     if (YYLIMIT == YYCURSOR)
   150         RET(TOKEN_EOI);
   160         RET(TOKEN_EOI);
   151 /*!re2c
   161 /*!re2c
   152     NEWLINE         { s->line++; goto scanner_loop; }
   162     NEWLINE         { s->line++; token = cursor-1; RET('\n'); }
   153     any             { goto singlelinecomment; }
   163     any             { goto singlelinecomment; }
   154 */
   164 */
   155 
   165 
   156 // !!! FIXME
   166 // !!! FIXME
   157 /*
   167 /*