author | Ryan C. Gordon <icculus@icculus.org> |
Sat, 14 Feb 2009 01:33:18 -0500 | |
changeset 616 | 9f087be64555 |
parent 601 | bb1484be4e1b |
child 631 | 5045dcc9fdaf |
permissions | -rw-r--r-- |
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 |
|
564
c669568326fb
Reworked preprocessor newline management.
Ryan C. Gordon <icculus@icculus.org>
parents:
555
diff
changeset
|
27 |
#define RET(t) do { update_state(s, cursor, token); return t; } while (0) |
555
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
28 |
#define YYCTYPE uchar |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
29 |
#define YYCURSOR cursor |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
30 |
#define YYLIMIT limit |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
31 |
#define YYMARKER s->lexer_marker |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
32 |
#define YYFILL(n) { if ((n) == 1) { RET(TOKEN_EOI); } } |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
33 |
|
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
34 |
static void update_state(IncludeState *s, const uchar *cur, const uchar *tok) |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
35 |
{ |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
36 |
s->bytes_left -= (unsigned int) (cur - ((const uchar *) s->source)); |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
37 |
s->source = (const char *) cur; |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
38 |
s->token = (const char *) tok; |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
39 |
} // update_state |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
40 |
|
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
41 |
Token preprocessor_internal_lexer(IncludeState *s) |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
42 |
{ |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
43 |
const uchar *cursor = (const uchar *) s->source; |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
44 |
const uchar *token; |
595
a72705c067dc
Handle lexing of comment ends better.
Ryan C. Gordon <icculus@icculus.org>
parents:
594
diff
changeset
|
45 |
const uchar *matchptr; |
555
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
46 |
const uchar *limit = cursor + s->bytes_left; |
564
c669568326fb
Reworked preprocessor newline management.
Ryan C. Gordon <icculus@icculus.org>
parents:
555
diff
changeset
|
47 |
int saw_newline = 0; |
555
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
48 |
|
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
49 |
scanner_loop: |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
50 |
token = cursor; |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
51 |
|
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
52 |
if (YYLIMIT == YYCURSOR) |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
53 |
RET(TOKEN_EOI); |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
54 |
|
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
55 |
/*!re2c |
596
8efa254e8840
Renamed "any" to "ANY" to match other rules.
Ryan C. Gordon <icculus@icculus.org>
parents:
595
diff
changeset
|
56 |
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
|
57 |
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
|
58 |
O = [0-7]; |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
59 |
D = [0-9]; |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
60 |
L = [a-zA-Z_]; |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
61 |
H = [a-fA-F0-9]; |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
62 |
E = [Ee] [+-]? D+; |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
63 |
FS = [fFlL]; |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
64 |
IS = [uUlL]*; |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
65 |
ESC = [\\] ([abfnrtv?'"\\] | "x" H+ | O+); |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
66 |
PP = "#" [ \t]*; |
594
de6f8df3b4fe
A couple endline fixes in the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
584
diff
changeset
|
67 |
NEWLINE = ("\r\n" | "\r" | "\n"); |
555
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
68 |
WHITESPACE = [ \t\v\f]+; |
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 |
|
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
71 |
/*!re2c |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
72 |
"/*" { goto multilinecomment; } |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
73 |
"//" { goto singlelinecomment; } |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
74 |
|
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
75 |
L (L|D)* { RET(TOKEN_IDENTIFIER); } |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
76 |
|
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
77 |
("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
|
78 |
(['] (ESC|ANY\[\r\n\\'])* [']) |
555
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
79 |
{ RET(TOKEN_INT_LITERAL); } |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
80 |
|
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
81 |
(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
|
82 |
{ RET(TOKEN_FLOAT_LITERAL); } |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
83 |
|
596
8efa254e8840
Renamed "any" to "ANY" to match other rules.
Ryan C. Gordon <icculus@icculus.org>
parents:
595
diff
changeset
|
84 |
(["] (ESC|ANY\[\r\n\\"])* ["]) |
555
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
85 |
{ RET(TOKEN_STRING_LITERAL); } |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
86 |
|
584
9aea8877564d
Updated lexer for HLSL.
Ryan C. Gordon <icculus@icculus.org>
parents:
564
diff
changeset
|
87 |
">>=" { RET(TOKEN_RSHIFTASSIGN); } |
9aea8877564d
Updated lexer for HLSL.
Ryan C. Gordon <icculus@icculus.org>
parents:
564
diff
changeset
|
88 |
"<<=" { RET(TOKEN_LSHIFTASSIGN); } |
9aea8877564d
Updated lexer for HLSL.
Ryan C. Gordon <icculus@icculus.org>
parents:
564
diff
changeset
|
89 |
"+=" { RET(TOKEN_ADDASSIGN); } |
9aea8877564d
Updated lexer for HLSL.
Ryan C. Gordon <icculus@icculus.org>
parents:
564
diff
changeset
|
90 |
"-=" { RET(TOKEN_SUBASSIGN); } |
9aea8877564d
Updated lexer for HLSL.
Ryan C. Gordon <icculus@icculus.org>
parents:
564
diff
changeset
|
91 |
"*=" { RET(TOKEN_MULTASSIGN); } |
9aea8877564d
Updated lexer for HLSL.
Ryan C. Gordon <icculus@icculus.org>
parents:
564
diff
changeset
|
92 |
"/=" { RET(TOKEN_DIVASSIGN); } |
9aea8877564d
Updated lexer for HLSL.
Ryan C. Gordon <icculus@icculus.org>
parents:
564
diff
changeset
|
93 |
"%=" { RET(TOKEN_MODASSIGN); } |
9aea8877564d
Updated lexer for HLSL.
Ryan C. Gordon <icculus@icculus.org>
parents:
564
diff
changeset
|
94 |
"^=" { RET(TOKEN_XORASSIGN); } |
9aea8877564d
Updated lexer for HLSL.
Ryan C. Gordon <icculus@icculus.org>
parents:
564
diff
changeset
|
95 |
"&=" { RET(TOKEN_ANDASSIGN); } |
9aea8877564d
Updated lexer for HLSL.
Ryan C. Gordon <icculus@icculus.org>
parents:
564
diff
changeset
|
96 |
"|=" { RET(TOKEN_ORASSIGN); } |
9aea8877564d
Updated lexer for HLSL.
Ryan C. Gordon <icculus@icculus.org>
parents:
564
diff
changeset
|
97 |
"++" { RET(TOKEN_INCREMENT); } |
9aea8877564d
Updated lexer for HLSL.
Ryan C. Gordon <icculus@icculus.org>
parents:
564
diff
changeset
|
98 |
"--" { RET(TOKEN_DECREMENT); } |
555
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
99 |
">>" { RET(TOKEN_RSHIFT); } |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
100 |
"<<" { RET(TOKEN_LSHIFT); } |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
101 |
"&&" { RET(TOKEN_ANDAND); } |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
102 |
"||" { RET(TOKEN_OROR); } |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
103 |
"<=" { RET(TOKEN_LEQ); } |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
104 |
">=" { RET(TOKEN_GEQ); } |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
105 |
"==" { RET(TOKEN_EQL); } |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
106 |
"!=" { RET(TOKEN_NEQ); } |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
107 |
"##" { RET(TOKEN_HASHHASH); } |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
108 |
"(" { RET('('); } |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
109 |
")" { RET(')'); } |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
110 |
"[" { RET('['); } |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
111 |
"]" { RET(']'); } |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
112 |
"." { RET('.'); } |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
113 |
"," { RET(','); } |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
114 |
"&" { RET('&'); } |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
115 |
"!" { RET('!'); } |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
116 |
"~" { RET('~'); } |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
117 |
"-" { RET('-'); } |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
118 |
"+" { RET('+'); } |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
119 |
"*" { RET('*'); } |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
120 |
"/" { RET('/'); } |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
121 |
"%" { RET('%'); } |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
122 |
"<" { RET('<'); } |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
123 |
">" { RET('>'); } |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
124 |
"^" { RET('^'); } |
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 |
|
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
134 |
PP "include" { RET(TOKEN_PP_INCLUDE); } |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
135 |
PP "line" { RET(TOKEN_PP_LINE); } |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
136 |
PP "define" { RET(TOKEN_PP_DEFINE); } |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
137 |
PP "undef" { RET(TOKEN_PP_UNDEF); } |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
138 |
PP "if" { RET(TOKEN_PP_IF); } |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
139 |
PP "ifdef" { RET(TOKEN_PP_IFDEF); } |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
140 |
PP "ifndef" { RET(TOKEN_PP_IFNDEF); } |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
141 |
PP "else" { RET(TOKEN_PP_ELSE); } |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
142 |
PP "elif" { RET(TOKEN_PP_ELIF); } |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
143 |
PP "endif" { RET(TOKEN_PP_ENDIF); } |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
144 |
PP "error" { RET(TOKEN_PP_ERROR); } |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
145 |
|
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
146 |
WHITESPACE { goto scanner_loop; } |
564
c669568326fb
Reworked preprocessor newline management.
Ryan C. Gordon <icculus@icculus.org>
parents:
555
diff
changeset
|
147 |
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
|
148 |
ANY { goto bad_chars; } |
555
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
149 |
*/ |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
150 |
|
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
151 |
multilinecomment: |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
152 |
if (YYLIMIT == YYCURSOR) |
601
bb1484be4e1b
Reworked and documented preprocessor tokens.
Ryan C. Gordon <icculus@icculus.org>
parents:
597
diff
changeset
|
153 |
RET(TOKEN_INCOMPLETE_COMMENT); |
595
a72705c067dc
Handle lexing of comment ends better.
Ryan C. Gordon <icculus@icculus.org>
parents:
594
diff
changeset
|
154 |
matchptr = cursor; |
555
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
155 |
// 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
|
156 |
/*!re2c |
564
c669568326fb
Reworked preprocessor newline management.
Ryan C. Gordon <icculus@icculus.org>
parents:
555
diff
changeset
|
157 |
"*\/" { |
c669568326fb
Reworked preprocessor newline management.
Ryan C. Gordon <icculus@icculus.org>
parents:
555
diff
changeset
|
158 |
if (saw_newline) |
c669568326fb
Reworked preprocessor newline management.
Ryan C. Gordon <icculus@icculus.org>
parents:
555
diff
changeset
|
159 |
RET('\n'); |
c669568326fb
Reworked preprocessor newline management.
Ryan C. Gordon <icculus@icculus.org>
parents:
555
diff
changeset
|
160 |
goto scanner_loop; |
c669568326fb
Reworked preprocessor newline management.
Ryan C. Gordon <icculus@icculus.org>
parents:
555
diff
changeset
|
161 |
} |
c669568326fb
Reworked preprocessor newline management.
Ryan C. Gordon <icculus@icculus.org>
parents:
555
diff
changeset
|
162 |
NEWLINE { |
c669568326fb
Reworked preprocessor newline management.
Ryan C. Gordon <icculus@icculus.org>
parents:
555
diff
changeset
|
163 |
s->line++; |
595
a72705c067dc
Handle lexing of comment ends better.
Ryan C. Gordon <icculus@icculus.org>
parents:
594
diff
changeset
|
164 |
token = matchptr; |
564
c669568326fb
Reworked preprocessor newline management.
Ryan C. Gordon <icculus@icculus.org>
parents:
555
diff
changeset
|
165 |
saw_newline = 1; |
c669568326fb
Reworked preprocessor newline management.
Ryan C. Gordon <icculus@icculus.org>
parents:
555
diff
changeset
|
166 |
goto multilinecomment; |
c669568326fb
Reworked preprocessor newline management.
Ryan C. Gordon <icculus@icculus.org>
parents:
555
diff
changeset
|
167 |
} |
596
8efa254e8840
Renamed "any" to "ANY" to match other rules.
Ryan C. Gordon <icculus@icculus.org>
parents:
595
diff
changeset
|
168 |
ANY { goto multilinecomment; } |
555
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
169 |
*/ |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
170 |
|
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
171 |
singlelinecomment: |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
172 |
if (YYLIMIT == YYCURSOR) |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
173 |
RET(TOKEN_EOI); |
595
a72705c067dc
Handle lexing of comment ends better.
Ryan C. Gordon <icculus@icculus.org>
parents:
594
diff
changeset
|
174 |
matchptr = cursor; |
555
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
175 |
/*!re2c |
595
a72705c067dc
Handle lexing of comment ends better.
Ryan C. Gordon <icculus@icculus.org>
parents:
594
diff
changeset
|
176 |
NEWLINE { s->line++; token = matchptr; RET('\n'); } |
596
8efa254e8840
Renamed "any" to "ANY" to match other rules.
Ryan C. Gordon <icculus@icculus.org>
parents:
595
diff
changeset
|
177 |
ANY { goto singlelinecomment; } |
555
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
178 |
*/ |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
179 |
|
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
180 |
bad_chars: |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
181 |
if (YYLIMIT == YYCURSOR) |
601
bb1484be4e1b
Reworked and documented preprocessor tokens.
Ryan C. Gordon <icculus@icculus.org>
parents:
597
diff
changeset
|
182 |
RET(TOKEN_BAD_CHARS); |
555
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
183 |
|
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
184 |
/*!re2c |
601
bb1484be4e1b
Reworked and documented preprocessor tokens.
Ryan C. Gordon <icculus@icculus.org>
parents:
597
diff
changeset
|
185 |
ANYLEGAL { cursor--; RET(TOKEN_BAD_CHARS); } |
597
832dbfa63509
Bogus chars in the lexer now return a token that signifies this.
Ryan C. Gordon <icculus@icculus.org>
parents:
596
diff
changeset
|
186 |
ANY { goto bad_chars; } |
555
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
187 |
*/ |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
188 |
|
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
189 |
assert(0 && "Shouldn't hit this code"); |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
190 |
RET(TOKEN_UNKNOWN); |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
191 |
} // preprocessor_internal_lexer |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
192 |
|
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
193 |
// 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
|
194 |