mojoshader_lexer.re
author Ryan C. Gordon <icculus@icculus.org>
Tue, 17 Feb 2009 08:40:03 -0500
changeset 642 624ab8696f9b
parent 635 be3b428802a1
child 648 243e35876142
permissions -rw-r--r--
Enormous amount of tapdancing to handle EOI better in the lexer.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
555
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     1
/**
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     2
 * MojoShader; generate shader programs from bytecode of compiled
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     3
 *  Direct3D shaders.
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     4
 *
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     5
 * Please see the file LICENSE.txt in the source's root directory.
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     6
 *
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     7
 *  This file written by Ryan C. Gordon.
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     8
 */
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     9
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    10
// This was originally based on examples/pp-c.re from re2c: http://re2c.org/
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    11
//   re2c is public domain code.
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    12
//
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    13
// You build mojoshader_lexer_preprocessor.c from the .re file with re2c...
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    14
// re2c -is -o mojoshader_lexer_preprocessor.c mojoshader_lexer_preprocessor.re
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    15
//
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    16
// Changes to the lexer are done to the .re file, not the C code!
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    17
//
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    18
// Please note that this isn't a perfect C lexer, since it is used for both
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    19
//  HLSL and shader assembly language, and follows the quirks of Microsoft's
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    20
//  tools.
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    21
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    22
#define __MOJOSHADER_INTERNAL__ 1
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    23
#include "mojoshader_internal.h"
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    24
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    25
typedef unsigned char uchar;
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    26
642
624ab8696f9b Enormous amount of tapdancing to handle EOI better in the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 635
diff changeset
    27
/*!max:re2c */
624ab8696f9b Enormous amount of tapdancing to handle EOI better in the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 635
diff changeset
    28
#define RET(t) do { update_state(s, eoi, cursor, token); return t; } while (0)
555
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    29
#define YYCTYPE uchar
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    30
#define YYCURSOR cursor
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    31
#define YYLIMIT limit
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    32
#define YYMARKER s->lexer_marker
642
624ab8696f9b Enormous amount of tapdancing to handle EOI better in the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 635
diff changeset
    33
#define YYFILL(n) { if ((n) == 1) { cursor = sentinel; limit = cursor + YYMAXFILL; eoi = 1; } }
555
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    34
642
624ab8696f9b Enormous amount of tapdancing to handle EOI better in the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 635
diff changeset
    35
static uchar sentinel[YYMAXFILL];
624ab8696f9b Enormous amount of tapdancing to handle EOI better in the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 635
diff changeset
    36
624ab8696f9b Enormous amount of tapdancing to handle EOI better in the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 635
diff changeset
    37
static void update_state(IncludeState *s, int eoi,
624ab8696f9b Enormous amount of tapdancing to handle EOI better in the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 635
diff changeset
    38
                         const uchar *cur, const uchar *tok)
555
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    39
{
642
624ab8696f9b Enormous amount of tapdancing to handle EOI better in the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 635
diff changeset
    40
    if (eoi)
624ab8696f9b Enormous amount of tapdancing to handle EOI better in the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 635
diff changeset
    41
    {
624ab8696f9b Enormous amount of tapdancing to handle EOI better in the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 635
diff changeset
    42
        s->bytes_left = 0;
624ab8696f9b Enormous amount of tapdancing to handle EOI better in the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 635
diff changeset
    43
        s->source = (const char *) s->source_base + s->orig_length;
624ab8696f9b Enormous amount of tapdancing to handle EOI better in the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 635
diff changeset
    44
        if ( (tok >= sentinel) && (tok < (sentinel+YYMAXFILL)) )
624ab8696f9b Enormous amount of tapdancing to handle EOI better in the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 635
diff changeset
    45
            s->token = s->source;
624ab8696f9b Enormous amount of tapdancing to handle EOI better in the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 635
diff changeset
    46
        else
624ab8696f9b Enormous amount of tapdancing to handle EOI better in the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 635
diff changeset
    47
            s->token = (const char *) tok;
624ab8696f9b Enormous amount of tapdancing to handle EOI better in the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 635
diff changeset
    48
    } // if
624ab8696f9b Enormous amount of tapdancing to handle EOI better in the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 635
diff changeset
    49
    else
624ab8696f9b Enormous amount of tapdancing to handle EOI better in the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 635
diff changeset
    50
    {
624ab8696f9b Enormous amount of tapdancing to handle EOI better in the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 635
diff changeset
    51
        s->bytes_left -= (unsigned int) (cur - ((const uchar *) s->source));
624ab8696f9b Enormous amount of tapdancing to handle EOI better in the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 635
diff changeset
    52
        s->source = (const char *) cur;
624ab8696f9b Enormous amount of tapdancing to handle EOI better in the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 635
diff changeset
    53
        s->token = (const char *) tok;
624ab8696f9b Enormous amount of tapdancing to handle EOI better in the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 635
diff changeset
    54
    } // else
555
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    55
} // update_state
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    56
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    57
Token preprocessor_internal_lexer(IncludeState *s)
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    58
{
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    59
    const uchar *cursor = (const uchar *) s->source;
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    60
    const uchar *token;
595
a72705c067dc Handle lexing of comment ends better.
Ryan C. Gordon <icculus@icculus.org>
parents: 594
diff changeset
    61
    const uchar *matchptr;
555
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    62
    const uchar *limit = cursor + s->bytes_left;
642
624ab8696f9b Enormous amount of tapdancing to handle EOI better in the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 635
diff changeset
    63
    int eoi = 0;
564
c669568326fb Reworked preprocessor newline management.
Ryan C. Gordon <icculus@icculus.org>
parents: 555
diff changeset
    64
    int saw_newline = 0;
555
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    65
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    66
scanner_loop:
642
624ab8696f9b Enormous amount of tapdancing to handle EOI better in the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 635
diff changeset
    67
    if (YYLIMIT == YYCURSOR) YYFILL(1);
555
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    68
    token = cursor;
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    69
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    70
/*!re2c
596
8efa254e8840 Renamed "any" to "ANY" to match other rules.
Ryan C. Gordon <icculus@icculus.org>
parents: 595
diff changeset
    71
    ANY = [\000-\377];
597
832dbfa63509 Bogus chars in the lexer now return a token that signifies this.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
    72
    ANYLEGAL = [a-zA-Z0-9_/'*=+%^&|!#<>()[{}.,~^:;? \t\v\f\r\n\-\]\\];
555
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    73
    O = [0-7];
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    74
    D = [0-9];
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    75
    L = [a-zA-Z_];
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    76
    H = [a-fA-F0-9];
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    77
    E = [Ee] [+-]? D+;
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    78
    FS = [fFlL];
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    79
    IS = [uUlL]*;
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    80
    ESC = [\\] ([abfnrtv?'"\\] | "x" H+ | O+);
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    81
    PP = "#" [ \t]*;
594
de6f8df3b4fe A couple endline fixes in the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 584
diff changeset
    82
    NEWLINE = ("\r\n" | "\r" | "\n");
555
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    83
    WHITESPACE = [ \t\v\f]+;
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    84
*/
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    85
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    86
/*!re2c
631
5045dcc9fdaf Lexer now handles '\\' continuation at the end of a line.
Ryan C. Gordon <icculus@icculus.org>
parents: 616
diff changeset
    87
    "\\" [ \t\v\f]* NEWLINE  { s->line++; goto scanner_loop; }
5045dcc9fdaf Lexer now handles '\\' continuation at the end of a line.
Ryan C. Gordon <icculus@icculus.org>
parents: 616
diff changeset
    88
555
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    89
    "/*"            { goto multilinecomment; }
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    90
    "//"            { goto singlelinecomment; }
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    91
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    92
    L (L|D)*        { RET(TOKEN_IDENTIFIER); }
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    93
    
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    94
    ("0" [xX] H+ IS?) | ("0" D+ IS?) | (D+ IS?) |
596
8efa254e8840 Renamed "any" to "ANY" to match other rules.
Ryan C. Gordon <icculus@icculus.org>
parents: 595
diff changeset
    95
    (['] (ESC|ANY\[\r\n\\'])* ['])
555
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    96
                    { RET(TOKEN_INT_LITERAL); }
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    97
    
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    98
    (D+ E FS?) | (D* "." D+ E? FS?) | (D+ "." D* E? FS?)
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    99
                    { RET(TOKEN_FLOAT_LITERAL); }
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   100
    
596
8efa254e8840 Renamed "any" to "ANY" to match other rules.
Ryan C. Gordon <icculus@icculus.org>
parents: 595
diff changeset
   101
    (["] (ESC|ANY\[\r\n\\"])* ["])
555
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   102
                    { RET(TOKEN_STRING_LITERAL); }
631
5045dcc9fdaf Lexer now handles '\\' continuation at the end of a line.
Ryan C. Gordon <icculus@icculus.org>
parents: 616
diff changeset
   103
584
9aea8877564d Updated lexer for HLSL.
Ryan C. Gordon <icculus@icculus.org>
parents: 564
diff changeset
   104
    ">>="           { RET(TOKEN_RSHIFTASSIGN); }
9aea8877564d Updated lexer for HLSL.
Ryan C. Gordon <icculus@icculus.org>
parents: 564
diff changeset
   105
    "<<="           { RET(TOKEN_LSHIFTASSIGN); }
9aea8877564d Updated lexer for HLSL.
Ryan C. Gordon <icculus@icculus.org>
parents: 564
diff changeset
   106
    "+="            { RET(TOKEN_ADDASSIGN); }
9aea8877564d Updated lexer for HLSL.
Ryan C. Gordon <icculus@icculus.org>
parents: 564
diff changeset
   107
    "-="            { RET(TOKEN_SUBASSIGN); }
9aea8877564d Updated lexer for HLSL.
Ryan C. Gordon <icculus@icculus.org>
parents: 564
diff changeset
   108
    "*="            { RET(TOKEN_MULTASSIGN); }
9aea8877564d Updated lexer for HLSL.
Ryan C. Gordon <icculus@icculus.org>
parents: 564
diff changeset
   109
    "/="            { RET(TOKEN_DIVASSIGN); }
9aea8877564d Updated lexer for HLSL.
Ryan C. Gordon <icculus@icculus.org>
parents: 564
diff changeset
   110
    "%="            { RET(TOKEN_MODASSIGN); }
9aea8877564d Updated lexer for HLSL.
Ryan C. Gordon <icculus@icculus.org>
parents: 564
diff changeset
   111
    "^="            { RET(TOKEN_XORASSIGN); }
9aea8877564d Updated lexer for HLSL.
Ryan C. Gordon <icculus@icculus.org>
parents: 564
diff changeset
   112
    "&="            { RET(TOKEN_ANDASSIGN); }
9aea8877564d Updated lexer for HLSL.
Ryan C. Gordon <icculus@icculus.org>
parents: 564
diff changeset
   113
    "|="            { RET(TOKEN_ORASSIGN); }
9aea8877564d Updated lexer for HLSL.
Ryan C. Gordon <icculus@icculus.org>
parents: 564
diff changeset
   114
    "++"            { RET(TOKEN_INCREMENT); }
9aea8877564d Updated lexer for HLSL.
Ryan C. Gordon <icculus@icculus.org>
parents: 564
diff changeset
   115
    "--"            { RET(TOKEN_DECREMENT); }
555
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   116
    ">>"            { RET(TOKEN_RSHIFT); }
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   117
    "<<"            { RET(TOKEN_LSHIFT); }
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   118
    "&&"            { RET(TOKEN_ANDAND); }
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   119
    "||"            { RET(TOKEN_OROR); }
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   120
    "<="            { RET(TOKEN_LEQ); }
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   121
    ">="            { RET(TOKEN_GEQ); }
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   122
    "=="            { RET(TOKEN_EQL); }
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   123
    "!="            { RET(TOKEN_NEQ); }
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   124
    "##"            { RET(TOKEN_HASHHASH); }
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   125
    "("             { RET('('); }
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   126
    ")"             { RET(')'); }
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   127
    "["             { RET('['); }
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   128
    "]"             { RET(']'); }
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   129
    "."             { RET('.'); }
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   130
    ","             { RET(','); }
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   131
    "&"             { RET('&'); }
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   132
    "!"             { RET('!'); }
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   133
    "~"             { RET('~'); }
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   134
    "-"             { RET('-'); }
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   135
    "+"             { RET('+'); }
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   136
    "*"             { RET('*'); }
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   137
    "/"             { RET('/'); }
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   138
    "%"             { RET('%'); }
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   139
    "<"             { RET('<'); }
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   140
    ">"             { RET('>'); }
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   141
    "^"             { RET('^'); }
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   142
    "|"             { RET('|'); }
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   143
    ":"             { RET(':'); }
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   144
    ";"             { RET(';'); }
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   145
    "{"             { RET('{'); }
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   146
    "}"             { RET('}'); }
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   147
    "="             { RET('='); }
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   148
    "?"             { RET('?'); }
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   149
642
624ab8696f9b Enormous amount of tapdancing to handle EOI better in the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 635
diff changeset
   150
    "\000"          { if (eoi) { RET(TOKEN_EOI); } goto bad_chars; }
624ab8696f9b Enormous amount of tapdancing to handle EOI better in the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 635
diff changeset
   151
555
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   152
    PP "include"    { RET(TOKEN_PP_INCLUDE); }
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   153
    PP "line"       { RET(TOKEN_PP_LINE); }
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   154
    PP "define"     { RET(TOKEN_PP_DEFINE); }
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   155
    PP "undef"      { RET(TOKEN_PP_UNDEF); }
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   156
    PP "if"         { RET(TOKEN_PP_IF); }
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   157
    PP "ifdef"      { RET(TOKEN_PP_IFDEF); }
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   158
    PP "ifndef"     { RET(TOKEN_PP_IFNDEF); }
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   159
    PP "else"       { RET(TOKEN_PP_ELSE); }
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   160
    PP "elif"       { RET(TOKEN_PP_ELIF); }
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   161
    PP "endif"      { RET(TOKEN_PP_ENDIF); }
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   162
    PP "error"      { RET(TOKEN_PP_ERROR); }
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   163
635
be3b428802a1 Try to make #error lexing match gcc's.
Ryan C. Gordon <icculus@icculus.org>
parents: 631
diff changeset
   164
    WHITESPACE      { if (s->report_whitespace) RET(' '); goto scanner_loop; }
564
c669568326fb Reworked preprocessor newline management.
Ryan C. Gordon <icculus@icculus.org>
parents: 555
diff changeset
   165
    NEWLINE         { s->line++; RET('\n'); }
597
832dbfa63509 Bogus chars in the lexer now return a token that signifies this.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   166
    ANY             { goto bad_chars; }
555
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   167
*/
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   168
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   169
multilinecomment:
642
624ab8696f9b Enormous amount of tapdancing to handle EOI better in the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 635
diff changeset
   170
    if (YYLIMIT == YYCURSOR) YYFILL(1);
595
a72705c067dc Handle lexing of comment ends better.
Ryan C. Gordon <icculus@icculus.org>
parents: 594
diff changeset
   171
    matchptr = cursor;
555
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   172
// The "*\/" is just to avoid screwing up text editor syntax highlighting.
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   173
/*!re2c
564
c669568326fb Reworked preprocessor newline management.
Ryan C. Gordon <icculus@icculus.org>
parents: 555
diff changeset
   174
    "*\/"           {
c669568326fb Reworked preprocessor newline management.
Ryan C. Gordon <icculus@icculus.org>
parents: 555
diff changeset
   175
                        if (saw_newline)
c669568326fb Reworked preprocessor newline management.
Ryan C. Gordon <icculus@icculus.org>
parents: 555
diff changeset
   176
                            RET('\n');
635
be3b428802a1 Try to make #error lexing match gcc's.
Ryan C. Gordon <icculus@icculus.org>
parents: 631
diff changeset
   177
                        else if (s->report_whitespace)
be3b428802a1 Try to make #error lexing match gcc's.
Ryan C. Gordon <icculus@icculus.org>
parents: 631
diff changeset
   178
                            RET(' ');
564
c669568326fb Reworked preprocessor newline management.
Ryan C. Gordon <icculus@icculus.org>
parents: 555
diff changeset
   179
                        goto scanner_loop;
c669568326fb Reworked preprocessor newline management.
Ryan C. Gordon <icculus@icculus.org>
parents: 555
diff changeset
   180
                    }
c669568326fb Reworked preprocessor newline management.
Ryan C. Gordon <icculus@icculus.org>
parents: 555
diff changeset
   181
    NEWLINE         {
c669568326fb Reworked preprocessor newline management.
Ryan C. Gordon <icculus@icculus.org>
parents: 555
diff changeset
   182
                        s->line++;
595
a72705c067dc Handle lexing of comment ends better.
Ryan C. Gordon <icculus@icculus.org>
parents: 594
diff changeset
   183
                        token = matchptr;
564
c669568326fb Reworked preprocessor newline management.
Ryan C. Gordon <icculus@icculus.org>
parents: 555
diff changeset
   184
                        saw_newline = 1;
c669568326fb Reworked preprocessor newline management.
Ryan C. Gordon <icculus@icculus.org>
parents: 555
diff changeset
   185
                        goto multilinecomment;
c669568326fb Reworked preprocessor newline management.
Ryan C. Gordon <icculus@icculus.org>
parents: 555
diff changeset
   186
                    }
642
624ab8696f9b Enormous amount of tapdancing to handle EOI better in the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 635
diff changeset
   187
    "\000"          {
624ab8696f9b Enormous amount of tapdancing to handle EOI better in the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 635
diff changeset
   188
                        if (eoi)
624ab8696f9b Enormous amount of tapdancing to handle EOI better in the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 635
diff changeset
   189
                            RET(TOKEN_INCOMPLETE_COMMENT);
624ab8696f9b Enormous amount of tapdancing to handle EOI better in the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 635
diff changeset
   190
                        goto multilinecomment;
624ab8696f9b Enormous amount of tapdancing to handle EOI better in the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 635
diff changeset
   191
                    }
596
8efa254e8840 Renamed "any" to "ANY" to match other rules.
Ryan C. Gordon <icculus@icculus.org>
parents: 595
diff changeset
   192
    ANY             { goto multilinecomment; }
555
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   193
*/
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   194
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   195
singlelinecomment:
642
624ab8696f9b Enormous amount of tapdancing to handle EOI better in the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 635
diff changeset
   196
    if (YYLIMIT == YYCURSOR) YYFILL(1);
595
a72705c067dc Handle lexing of comment ends better.
Ryan C. Gordon <icculus@icculus.org>
parents: 594
diff changeset
   197
    matchptr = cursor;
555
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   198
/*!re2c
595
a72705c067dc Handle lexing of comment ends better.
Ryan C. Gordon <icculus@icculus.org>
parents: 594
diff changeset
   199
    NEWLINE         { s->line++; token = matchptr; RET('\n'); }
642
624ab8696f9b Enormous amount of tapdancing to handle EOI better in the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 635
diff changeset
   200
    "\000"          { if (eoi) { RET(TOKEN_EOI); } goto singlelinecomment; }
596
8efa254e8840 Renamed "any" to "ANY" to match other rules.
Ryan C. Gordon <icculus@icculus.org>
parents: 595
diff changeset
   201
    ANY             { goto singlelinecomment; }
555
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   202
*/
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   203
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   204
bad_chars:
642
624ab8696f9b Enormous amount of tapdancing to handle EOI better in the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 635
diff changeset
   205
    if (YYLIMIT == YYCURSOR) YYFILL(1);
555
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   206
/*!re2c
601
bb1484be4e1b Reworked and documented preprocessor tokens.
Ryan C. Gordon <icculus@icculus.org>
parents: 597
diff changeset
   207
    ANYLEGAL        { cursor--; RET(TOKEN_BAD_CHARS); }
642
624ab8696f9b Enormous amount of tapdancing to handle EOI better in the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 635
diff changeset
   208
    "\000"          {
624ab8696f9b Enormous amount of tapdancing to handle EOI better in the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 635
diff changeset
   209
                        if (eoi)
624ab8696f9b Enormous amount of tapdancing to handle EOI better in the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 635
diff changeset
   210
                        {
624ab8696f9b Enormous amount of tapdancing to handle EOI better in the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 635
diff changeset
   211
                            assert( !((token >= sentinel) &&
624ab8696f9b Enormous amount of tapdancing to handle EOI better in the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 635
diff changeset
   212
                                     (token < sentinel+YYMAXFILL)) );
624ab8696f9b Enormous amount of tapdancing to handle EOI better in the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 635
diff changeset
   213
                            eoi = 0;
624ab8696f9b Enormous amount of tapdancing to handle EOI better in the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 635
diff changeset
   214
                            cursor = (uchar *) s->source_base + s->orig_length;
624ab8696f9b Enormous amount of tapdancing to handle EOI better in the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 635
diff changeset
   215
                            RET(TOKEN_BAD_CHARS);  // next call will be EOI.
624ab8696f9b Enormous amount of tapdancing to handle EOI better in the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 635
diff changeset
   216
                        }
624ab8696f9b Enormous amount of tapdancing to handle EOI better in the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 635
diff changeset
   217
                        goto bad_chars;
624ab8696f9b Enormous amount of tapdancing to handle EOI better in the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 635
diff changeset
   218
                    }
624ab8696f9b Enormous amount of tapdancing to handle EOI better in the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 635
diff changeset
   219
597
832dbfa63509 Bogus chars in the lexer now return a token that signifies this.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   220
    ANY             { goto bad_chars; }
555
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   221
*/
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   222
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   223
    assert(0 && "Shouldn't hit this code");
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   224
    RET(TOKEN_UNKNOWN);
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   225
} // preprocessor_internal_lexer
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   226
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   227
// end of mojoshader_lexer_preprocessor.re (or .c) ...
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   228