temporarily disable elisp exception tests
[bpt/guile.git] / libguile / c-tokenize.lex
1 %top{
2 /* Include <config.h> before anything else because Gnulib headers such
3 as <stdio.h> rely on it.
4
5 However, when cross-compiling, don't include <config.h> because it
6 contains information about the host, not about the build. */
7 #ifndef CROSS_COMPILING
8 # include <config.h>
9 #endif
10 }
11
12 %option noyywrap
13 %option nounput
14 %pointer
15
16 EOL \n
17 SPACE [ \t\v\f]
18 WS [ \t\v\n\f]
19 DIGIT [0-9]
20 LETTER [a-zA-Z_]
21 OCTDIGIT [0-7]
22 HEXDIGIT [a-fA-F0-9]
23 EXPONENT [Ee][+-]?{DIGIT}+
24 FLOQUAL (f|F|l|L)
25 INTQUAL (l|L|ll|LL|lL|Ll|u|U)
26
27 %{
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <string.h>
31
32 /* Prevent compilation of static input() function in generated scanner
33 code. This function is never actually used, and GCC 4.3 will emit
34 an error for that. */
35 #define YY_NO_INPUT
36
37 int filter_snarfage = 0;
38 int print = 1;
39
40 enum t_state {
41 SKIP,
42 MULTILINE,
43 MULTILINE_COOKIE,
44 COOKIE
45 };
46
47 enum t_state state = SKIP;
48 int cookie_was_last = 0;
49
50 #define OUT_RAW(type,text) if (print) printf ("(%s . \"%s\")\n", #type, text)
51
52 #define OUT_T(type) OUT_RAW (type, yytext)
53 #define OUT_S if (print) printf ("%s\n", yytext)
54 #define OUT(type) if (print) printf ("%s\n", #type)
55
56 #define IS_COOKIE cookie_was_last = 1
57 #define IS_NOT_COOKIE cookie_was_last = 0
58
59 %}
60
61 %%
62
63 \/\*(\n|[^*]|\*[^/])*\*\/ { OUT_T (comment); }
64
65 ({SPACE}*(\\\n)*{SPACE}*)+ ;
66
67 ({SPACE}*\n*{SPACE}*)+ { OUT(eol); }
68
69 #.*\n { OUT(hash); IS_NOT_COOKIE; }
70
71 {LETTER}({LETTER}|{DIGIT})* { OUT_T (id); IS_NOT_COOKIE; }
72
73 0[xX]{HEXDIGIT}+{INTQUAL}? { OUT_RAW (int_hex, yytext + 2); IS_NOT_COOKIE; }
74 0{OCTDIGIT}+{INTQUAL}? { OUT_RAW (int_oct, yytext + 1); IS_NOT_COOKIE; }
75 {DIGIT}+{INTQUAL}? { OUT_T (int_dec); IS_NOT_COOKIE; }
76
77 L?\'(\\.|[^\\\'])+\' { OUT_T (char); IS_NOT_COOKIE; }
78
79 {DIGIT}+{EXPONENT}{FLOQUAL}? { OUT_T (flo_dec); IS_NOT_COOKIE; }
80 {DIGIT}*"."{DIGIT}+({EXPONENT})?{FLOQUAL}? { OUT_T (flo_dec); IS_NOT_COOKIE; }
81 {DIGIT}+"."{DIGIT}*({EXPONENT})?{FLOQUAL}? { OUT_T (flo_dec); IS_NOT_COOKIE; }
82
83 L?\"(\\.|[^\\\"])*\" { OUT_S; IS_NOT_COOKIE; }
84
85 "..." { OUT (ellipsis); IS_NOT_COOKIE; }
86
87 ">>=" { OUT (shift_right_assign); IS_NOT_COOKIE; }
88 "<<=" { OUT (shift_left_assign); IS_NOT_COOKIE; }
89 "+=" { OUT (add_assign); IS_NOT_COOKIE; }
90 "-=" { OUT (sub_assign); IS_NOT_COOKIE; }
91 "*=" { OUT (mul-assign); IS_NOT_COOKIE; }
92 "/=" { OUT (div_assign); IS_NOT_COOKIE; }
93 "%=" { OUT (mod_assign); IS_NOT_COOKIE; }
94 "&=" { OUT (logand_assign); IS_NOT_COOKIE; }
95 "^=" { OUT (logxor_assign); IS_NOT_COOKIE; }
96 "|=" { OUT (logior_assign); IS_NOT_COOKIE; }
97 ">>" { OUT (right_shift); IS_NOT_COOKIE; }
98 "<<" { OUT (left_shift); IS_NOT_COOKIE; }
99 "++" { OUT (inc); IS_NOT_COOKIE; }
100 "--" { OUT (dec); IS_NOT_COOKIE; }
101 "->" { OUT (ptr); IS_NOT_COOKIE; }
102 "&&" { OUT (and); IS_NOT_COOKIE; }
103 "||" { OUT (or); IS_NOT_COOKIE; }
104 "<=" { OUT (le); IS_NOT_COOKIE; }
105 ">=" { OUT (ge); IS_NOT_COOKIE; }
106 "==" { OUT (eq); IS_NOT_COOKIE; }
107 "!=" { OUT (ne); IS_NOT_COOKIE; }
108 ";" { OUT (semicolon); IS_NOT_COOKIE; }
109
110 ("{"|"<%") {
111 OUT (brace_open);
112 if (filter_snarfage && cookie_was_last && state == COOKIE)
113 state = MULTILINE;
114 IS_NOT_COOKIE; }
115
116 ("}"|"%>") {
117 OUT (brace_close);
118 if (filter_snarfage && cookie_was_last && state == MULTILINE_COOKIE) {
119 state = SKIP;
120 print = 0;
121 }
122 IS_NOT_COOKIE; }
123
124 "," { OUT (comma); IS_NOT_COOKIE; }
125 ":" { OUT (colon); IS_NOT_COOKIE; }
126 "=" { OUT (assign); IS_NOT_COOKIE; }
127 "(" { OUT (paren_open); IS_NOT_COOKIE; }
128 ")" { OUT (paren_close); IS_NOT_COOKIE; }
129 ("["|"<:") { OUT (bracket_open); IS_NOT_COOKIE; }
130 ("]"|":>") { OUT (bracket_close); IS_NOT_COOKIE; }
131 "." { OUT (dot); IS_NOT_COOKIE; }
132 "&" { OUT (amp); IS_NOT_COOKIE; }
133 "!" { OUT (bang); IS_NOT_COOKIE; }
134 "~" { OUT (tilde); IS_NOT_COOKIE; }
135 "-" { OUT (minus); IS_NOT_COOKIE; }
136 "+" { OUT (plus); IS_NOT_COOKIE; }
137 "*" { OUT (star); IS_NOT_COOKIE; }
138 "/" { OUT (slash); IS_NOT_COOKIE; }
139 "%" { OUT (percent); IS_NOT_COOKIE; }
140 "<" { OUT (lt); IS_NOT_COOKIE; }
141 ">" { OUT (gt); IS_NOT_COOKIE; }
142
143 \^{WS}*\^ {
144 if (filter_snarfage)
145 switch (state) {
146 case SKIP:
147 state = COOKIE;
148 print = 1;
149 OUT (snarf_cookie);
150 break;
151 case MULTILINE:
152 case MULTILINE_COOKIE:
153 state = MULTILINE_COOKIE;
154 OUT (snarf_cookie);
155 break;
156 case COOKIE:
157 state = SKIP;
158 OUT (snarf_cookie);
159 print = 0;
160 break;
161 default:
162 /* whoops */
163 abort ();
164 break;
165 }
166 else
167 OUT (snarf_cookie);
168
169 IS_COOKIE; }
170
171 "^" { OUT (caret); IS_NOT_COOKIE; }
172 "|" { OUT (pipe); IS_NOT_COOKIE; }
173 "?" { OUT (question); IS_NOT_COOKIE; }
174
175 . { fprintf (stderr, "*%s", yytext); fflush (stderr); IS_NOT_COOKIE; }
176
177 %%
178
179 int
180 main (int argc, char *argv[])
181 {
182 if (argc > 1 && !strcmp (argv[1], "--filter-snarfage")) {
183 filter_snarfage = 1;
184 print = 0;
185 }
186
187 yylex ();
188
189 return EXIT_SUCCESS;
190 }
191
192 /*
193 Local Variables:
194 c-file-style: "gnu"
195 End:
196 */