tokstart => ts and tokend => te
[ragel.git] / test / cppscan6.rl
blobed82fe6caaee8f46ab27b74a49df0269bfb9f662
1 /*
2  * @LANG: indep
3  *
4  * const char *data = ts;
5  * int len = te - ts;
6  * cout << "<" << tok << "> ";
7  * for ( int i = 0; i < len; i++ )
8  *     cout << data[i];
9  * cout << '\n';
10  */
11 ptr ts;
12 ptr te;
13 int act;
14 int token;
16 %%{
17         machine scanner;
19         action comment {
20                 token = 242;
21                 prints "<";
22                 printi token;
23                 prints "> ";
24                 print_token;
25                 prints "\n";
26         }
29         main := |*
31         # Single and double literals.
32         ( 'L'? "'" ( [^'\\\n] | '\\' any )* "'" ) 
33                 => { 
34                         token = 193;
35                         prints "<";
36                         printi token;
37                         prints "> ";
38                         print_token;
39                         prints "\n";
40                 };
41         ( 'L'? '"' ( [^"\\\n] | '\\' any )* '"' ) 
42                 => { 
43                         token = 192;
44                         prints "<";
45                         printi token;
46                         prints "> ";
47                         print_token;
48                         prints "\n";
49                 };
51         # Identifiers
52         ( [a-zA-Z_] [a-zA-Z0-9_]* ) 
53                 =>{
54                         token = 195;
55                         prints "<";
56                         printi token;
57                         prints "> ";
58                         print_token;
59                         prints "\n";
60                 };
62         # Floating literals.
63         fract_const = digit* '.' digit+ | digit+ '.';
64         exponent = [eE] [+\-]? digit+;
65         float_suffix = [flFL];
67         ( fract_const exponent? float_suffix? |
68                 digit+ exponent float_suffix? ) 
69                 => {
70                         token = 194;
71                         prints "<";
72                         printi token;
73                         prints "> ";
74                         print_token;
75                         prints "\n";
76                 };
77         
78         # Integer decimal. Leading part buffered by float.
79         ( ( '0' | [1-9] [0-9]* ) [ulUL]? ) 
80                 => {
81                         token = 218;
82                         prints "<";
83                         printi token;
84                         prints "> ";
85                         print_token;
86                         prints "\n";
87                 };
89         # Integer octal. Leading part buffered by float.
90         ( '0' [0-9]+ [ulUL]? ) 
91                 => {
92                         token = 219;
93                         prints "<";
94                         printi token;
95                         prints "> ";
96                         print_token;
97                         prints "\n";
98                 };
100         # Integer hex. Leading 0 buffered by float.
101         ( '0' ( 'x' [0-9a-fA-F]+ [ulUL]? ) ) 
102                 => {
103                         token = 220;
104                         prints "<";
105                         printi token;
106                         prints "> ";
107                         print_token;
108                         prints "\n";
109                 };
111         # Only buffer the second item, first buffered by symbol.
112         '::' => {
113                 token = 197;
114                 prints "<";
115                 printi token;
116                 prints "> ";
117                 print_token;
118                 prints "\n";
119         };
120         '==' => {
121                 token = 223;
122                 prints "<";
123                 printi token;
124                 prints "> ";
125                 print_token;
126                 prints "\n";
127         };
128         '!=' => {
129                 token = 224;
130                 prints "<";
131                 printi token;
132                 prints "> ";
133                 print_token;
134                 prints "\n";
135         };
136         '&&' => {
137                 token = 225;
138                 prints "<";
139                 printi token;
140                 prints "> ";
141                 print_token;
142                 prints "\n";
143         };
144         '||' => {
145                 token = 226;
146                 prints "<";
147                 printi token;
148                 prints "> ";
149                 print_token;
150                 prints "\n";
151         };
152         '*=' => {
153                 token = 227;
154                 prints "<";
155                 printi token;
156                 prints "> ";
157                 print_token;
158                 prints "\n";
159         };
160         '/=' => {
161                 token = 228;
162                 prints "<";
163                 printi token;
164                 prints "> ";
165                 print_token;
166                 prints "\n";
167         };
168         '%=' => {
169                 token = 229;
170                 prints "<";
171                 printi token;
172                 prints "> ";
173                 print_token;
174                 prints "\n";
175         };
176         '+=' => {
177                 token = 230;
178                 prints "<";
179                 printi token;
180                 prints "> ";
181                 print_token;
182                 prints "\n";
183         };
184         '-=' => {
185                 token = 231;
186                 prints "<";
187                 printi token;
188                 prints "> ";
189                 print_token;
190                 prints "\n";
191         };
192         '&=' => {
193                 token = 232;
194                 prints "<";
195                 printi token;
196                 prints "> ";
197                 print_token;
198                 prints "\n";
199         };
200         '^=' => {
201                 token = 233;
202                 prints "<";
203                 printi token;
204                 prints "> ";
205                 print_token;
206                 prints "\n";
207         };
208         '|=' => {
209                 token = 234;
210                 prints "<";
211                 printi token;
212                 prints "> ";
213                 print_token;
214                 prints "\n";
215         };
216         '++' => {
217                 token = 212;
218                 prints "<";
219                 printi token;
220                 prints "> ";
221                 print_token;
222                 prints "\n";
223         };
224         '--' => {
225                 token = 213;
226                 prints "<";
227                 printi token;
228                 prints "> ";
229                 print_token;
230                 prints "\n";
231         };
232         '->' => {
233                 token = 211;
234                 prints "<";
235                 printi token;
236                 prints "> ";
237                 print_token;
238                 prints "\n";
239         };
240         '->*' => {
241                 token = 214;
242                 prints "<";
243                 printi token;
244                 prints "> ";
245                 print_token;
246                 prints "\n";
247         };
248         '.*' => {
249                 token = 215;
250                 prints "<";
251                 printi token;
252                 prints "> ";
253                 print_token;
254                 prints "\n";
255         };
257         # Three char compounds, first item already buffered.
258         '...' => {
259                 token = 240;
260                 prints "<";
261                 printi token;
262                 prints "> ";
263                 print_token;
264                 prints "\n";
265         };
267         # Single char symbols.
268         ( punct - [_"'] ) => {
269                 token = first_token_char;
270                 prints "<";
271                 printi token;
272                 prints "> ";
273                 print_token;
274                 prints "\n";
275         };
277         # Comments and whitespace.
278         '/!' ( any* $0 '!/' @1 ) => comment;
279         '//' ( any* $0 '\n' @1 ) => comment;
280         ( any - 33..126 )+ => { 
281                 token = 241;
282                 prints "<";
283                 printi token;
284                 prints "> ";
285                 print_token;
286                 prints "\n";
287         };
288         *|;
290 /* _____INPUT_____
291 "\"\\\"hi\" /!\n!/\n44 .44\n44. 44\n44 . 44\n44.44\n_hithere22"
292 "'\\''\"\\n\\d'\\\"\"\nhi\n99\n.99\n99e-4\n->*\n||\n0x98\n0x\n//\n/! * !/"
293 "'\n'\n"
294 _____INPUT_____ */
295 /* _____OUTPUT_____
296 <192> "\"hi"
297 <241>  
298 <242> /!
300 <241> 
302 <218> 44
303 <241>  
304 <194> .44
305 <241> 
307 <194> 44.
308 <241>  
309 <218> 44
310 <241> 
312 <218> 44
313 <241>  
314 <46> .
315 <241>  
316 <218> 44
317 <241> 
319 <194> 44.44
320 <241> 
322 <195> _hithere22
323 ACCEPT
324 <193> '\''
325 <192> "\n\d'\""
326 <241> 
328 <195> hi
329 <241> 
331 <218> 99
332 <241> 
334 <194> .99
335 <241> 
337 <194> 99e-4
338 <241> 
340 <214> ->*
341 <241> 
343 <226> ||
344 <241> 
346 <220> 0x98
347 <241> 
349 <218> 0
350 <195> x
351 <241> 
353 <242> //
355 <242> /! * !/
356 ACCEPT
357 FAIL
358 _____OUTPUT_____ */