mojoshader_lexer.re
changeset 679 3892ebde7d99
parent 651 05ad72d120a5
child 690 4710df464f13
equal deleted inserted replaced
678:9fa2eb7d7871 679:3892ebde7d99
    58 } // update_state
    58 } // update_state
    59 
    59 
    60 Token preprocessor_lexer(IncludeState *s)
    60 Token preprocessor_lexer(IncludeState *s)
    61 {
    61 {
    62     const uchar *cursor = (const uchar *) s->source;
    62     const uchar *cursor = (const uchar *) s->source;
    63     const uchar *token;
    63     const uchar *token = cursor;
    64     const uchar *matchptr;
    64     const uchar *matchptr;
    65     const uchar *limit = cursor + s->bytes_left;
    65     const uchar *limit = cursor + s->bytes_left;
    66     int eoi = 0;
    66     int eoi = 0;
    67     int saw_newline = 0;
    67     int saw_newline = 0;
    68 
       
    69 scanner_loop:
       
    70     if (YYLIMIT == YYCURSOR) YYFILL(1);
       
    71     token = cursor;
       
    72 
    68 
    73 /*!re2c
    69 /*!re2c
    74     ANY = [\000-\377];
    70     ANY = [\000-\377];
    75     ANYLEGAL = [a-zA-Z0-9_/'*=+%^&|!#<>()[{}.,~^:;? \t\v\f\r\n\-\]\\];
    71     ANYLEGAL = [a-zA-Z0-9_/'*=+%^&|!#<>()[{}.,~^:;? \t\v\f\r\n\-\]\\];
    76     O = [0-7];
    72     O = [0-7];
    83     ESC = [\\] ([abfnrtv?'"\\] | "x" H+ | O+);
    79     ESC = [\\] ([abfnrtv?'"\\] | "x" H+ | O+);
    84     PP = "#" [ \t]*;
    80     PP = "#" [ \t]*;
    85     NEWLINE = ("\r\n" | "\r" | "\n");
    81     NEWLINE = ("\r\n" | "\r" | "\n");
    86     WHITESPACE = [ \t\v\f]+;
    82     WHITESPACE = [ \t\v\f]+;
    87 */
    83 */
       
    84 
       
    85     // preprocessor directives are only valid at start of line.
       
    86     if (s->tokenval == ((Token) '\n'))
       
    87         goto ppdirective;  // may jump back to scanner_loop.
       
    88 
       
    89 scanner_loop:
       
    90     if (YYLIMIT == YYCURSOR) YYFILL(1);
       
    91     token = cursor;
    88 
    92 
    89 /*!re2c
    93 /*!re2c
    90     "\\" [ \t\v\f]* NEWLINE  { s->line++; goto scanner_loop; }
    94     "\\" [ \t\v\f]* NEWLINE  { s->line++; goto scanner_loop; }
    91 
    95 
    92     "/*"            { goto multilinecomment; }
    96     "/*"            { goto multilinecomment; }
   150     "="             { RET('='); }
   154     "="             { RET('='); }
   151     "?"             { RET('?'); }
   155     "?"             { RET('?'); }
   152 
   156 
   153     "\000"          { if (eoi) { RET(TOKEN_EOI); } goto bad_chars; }
   157     "\000"          { if (eoi) { RET(TOKEN_EOI); } goto bad_chars; }
   154 
   158 
   155     PP "include"    { RET(TOKEN_PP_INCLUDE); }
       
   156     PP "line"       { RET(TOKEN_PP_LINE); }
       
   157     PP "define"     { RET(TOKEN_PP_DEFINE); }
       
   158     PP "undef"      { RET(TOKEN_PP_UNDEF); }
       
   159     PP "if"         { RET(TOKEN_PP_IF); }
       
   160     PP "ifdef"      { RET(TOKEN_PP_IFDEF); }
       
   161     PP "ifndef"     { RET(TOKEN_PP_IFNDEF); }
       
   162     PP "else"       { RET(TOKEN_PP_ELSE); }
       
   163     PP "elif"       { RET(TOKEN_PP_ELIF); }
       
   164     PP "endif"      { RET(TOKEN_PP_ENDIF); }
       
   165     PP "error"      { RET(TOKEN_PP_ERROR); }
       
   166 
       
   167     WHITESPACE      { if (s->report_whitespace) RET(' '); goto scanner_loop; }
   159     WHITESPACE      { if (s->report_whitespace) RET(' '); goto scanner_loop; }
   168     NEWLINE         { s->line++; RET('\n'); }
   160     NEWLINE         { s->line++; RET('\n'); }
   169     ANY             { goto bad_chars; }
   161     ANY             { goto bad_chars; }
   170 */
   162 */
   171 
   163 
   200     matchptr = cursor;
   192     matchptr = cursor;
   201 /*!re2c
   193 /*!re2c
   202     NEWLINE         { s->line++; token = matchptr; RET('\n'); }
   194     NEWLINE         { s->line++; token = matchptr; RET('\n'); }
   203     "\000"          { if (eoi) { RET(TOKEN_EOI); } goto singlelinecomment; }
   195     "\000"          { if (eoi) { RET(TOKEN_EOI); } goto singlelinecomment; }
   204     ANY             { goto singlelinecomment; }
   196     ANY             { goto singlelinecomment; }
       
   197 */
       
   198 
       
   199 ppdirective:
       
   200     if (YYLIMIT == YYCURSOR) YYFILL(1);
       
   201 /*!re2c
       
   202         PP "include"    { RET(TOKEN_PP_INCLUDE); }
       
   203         PP "line"       { RET(TOKEN_PP_LINE); }
       
   204         PP "define"     { RET(TOKEN_PP_DEFINE); }
       
   205         PP "undef"      { RET(TOKEN_PP_UNDEF); }
       
   206         PP "if"         { RET(TOKEN_PP_IF); }
       
   207         PP "ifdef"      { RET(TOKEN_PP_IFDEF); }
       
   208         PP "ifndef"     { RET(TOKEN_PP_IFNDEF); }
       
   209         PP "else"       { RET(TOKEN_PP_ELSE); }
       
   210         PP "elif"       { RET(TOKEN_PP_ELIF); }
       
   211         PP "endif"      { RET(TOKEN_PP_ENDIF); }
       
   212         PP "error"      { RET(TOKEN_PP_ERROR); }
       
   213         WHITESPACE      { goto ppdirective; }
       
   214         ANY             { cursor=(const uchar*)s->source; goto scanner_loop; }
   205 */
   215 */
   206 
   216 
   207 bad_chars:
   217 bad_chars:
   208     if (YYLIMIT == YYCURSOR) YYFILL(1);
   218     if (YYLIMIT == YYCURSOR) YYFILL(1);
   209 /*!re2c
   219 /*!re2c