1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
|
/****************************************************************************
**
** Lexical analyzer for meta object compiler
**
** Created : 930417
**
** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
**
** This file is part of the TQt GUI Toolkit.
**
** This file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free
** Software Foundation and appearing in the files LICENSE.GPL2
** and LICENSE.GPL3 included in the packaging of this file.
** Alternatively you may (at your option) use any later version
** of the GNU General Public License if such license has been
** publicly approved by Trolltech ASA (or its successors, if any)
** and the KDE Free TQt Foundation.
**
** Please review the following information to ensure GNU General
** Public Licensing requirements will be met:
** http://trolltech.com/products/qt/licenses/licensing/opensource/.
** If you are unsure which license is appropriate for your use, please
** review the following information:
** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
** or contact the sales department at sales@trolltech.com.
**
** This file may be used under the terms of the Q Public License as
** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
** included in the packaging of this file. Licensees holding valid TQt
** Commercial licenses may use this file in accordance with the TQt
** Commercial License Agreement provided with the Software.
**
** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
** herein.
**
*****************************************************************************/
%{
#ifdef MOC_YACC_CODE
#ifdef MOC_MWERKS_PLUGIN
#ifdef Q_OS_MAC9
# define isascii(c) ((int)( (unsigned int) (c) <= (unsigned char)0x7F ))
#endif
const char *buf_buffer = NULL;
long buf_size_total = 0, buf_index = 0;
#define YY_INPUT(buf, result, max_size) \
{ \
if(buf_index < buf_size_total ) { \
while(!isascii(buf_buffer[buf_index])) buf_index++; \
int ms = ((max_size < buf_size_total) ? max_size : buf_size_total); \
for(result = 0; result < ms; result++) { \
char c = buf_buffer[buf_index + result]; \
if(!isascii(c)) { \
buf_index++; \
break; \
} \
buf[result] = c == '\r' ? '\n' : c; \
} \
buf_index += result; \
} else result = YY_NULL; \
}
#endif
#include "ntqstring.h"
#define input yyinput // yyinput in C++
#define X if(lexDebug){fprintf(stderr,"LEX (%i) : %s\n",lineNo,yytext);};
#define Y if(lexDebug){fprintf(stderr,"LEX (%i) : %s\n",lineNo,yytext);};
/*
#define Y if(lexDebug){fprintf(stderr,"LEX (%i) : %s updates level to %i\n"\
,lineNo,yytext,templLevel);};
*/
#define Z if(lexDebug){fprintf(stderr,"LEX (%i) : skipped the string %s\"\n"\
,lineNo,yytext);};
#define BEGIN_INSIDE
#define linput() \
( (c = input()) == '\n' ? (lineNo++, c) : (c == EOF) ? 0 : c )
#include <string.h>
#include <stdlib.h>
int classPLevel = 1; /* Depth of nested curly braces in IN_CLASS */
int namespacePLevel = 1; /* Depth of nested curly braces in IN_NAMESPACE */
int expLevel = 1; /* Depth of nested parentheses in IN_EXPR */
int enumLevel = 1; /* Depth of nested parentheses in IN_ENUM */
int fctLevel = 1; /* Depth of nested parentheses in IN_FCT */
int templLevel = 1; /* Depth of levels in IN_TEMPL_ARGS */
int lastState = 0; /* Remembers the state when a
MOC_SKIP_BEGIN is encountered */
int skipLevel = 0; /* Depth of MOC_SKIP_BEGINs */
class TQString;
extern void addExpressionChar( const char );
extern void addExpressionString( const char * );
extern void moc_warn( const char *msg );
%}
%start OUTSIDE QT_DEF IN_CLASS IN_NAMESPACE IN_ENUM IN_EXPR IN_DEF_ARG IN_FCT IN_TEMPL_ARGS GIMME_SEMICOLON SKIP IN_PROPERTY IN_CLASSINFO
ALMOSTSTRING \"([^"\n\\]|\\(.|\n))*
STRING {ALMOSTSTRING}\"
%%
<OUTSIDE>"class" { X;
BEGIN QT_DEF;
return CLASS; }
<OUTSIDE>"namespace" { X;
BEGIN QT_DEF;
return NAMESPACE; }
<OUTSIDE>"using" { X;
BEGIN QT_DEF;
return USING; }
<OUTSIDE>"template" { X;
BEGIN QT_DEF;
return TEMPLATE; }
<QT_DEF>"TQ_OBJECT" { X; return TQ_OBJECT; }
<QT_DEF>"signals" { X; return SIGNALS; }
<QT_DEF>"slots" { X; return SLOTS; }
<QT_DEF>"TQ_CLASSINFO" { X; return TQ_CLASSINFO; }
<QT_DEF>"TQ_PROPERTY" { X; return TQ_PROPERTY; }
<QT_DEF>"TQ_OVERRIDE" { X; return TQ_OVERRIDE; }
<QT_DEF>"TQ_ENUMS" { X; return TQ_ENUMS; }
<QT_DEF>"TQ_SETS" { X; return TQ_SETS; }
<IN_FCT>"{" { fctLevel++;Y; }
<IN_FCT>"}" { fctLevel--;Y;if (fctLevel==0){X;return '}';}}
<IN_CLASS>"{" { classPLevel++;Y; }
<IN_CLASS>"}" { classPLevel--;Y;if (classPLevel == 0)
{X;return '}';} }
<IN_CLASS>"public" { X;if( classPLevel == 1 ) return PUBLIC; }
<IN_CLASS>"protected" { X;if( classPLevel == 1 ) return PROTECTED; }
<IN_CLASS>"private" { X;if( classPLevel == 1 ) return PRIVATE; }
<IN_CLASS>"signals" { X;if( classPLevel == 1 ) return SIGNALS; }
<IN_CLASS>"slots" { X;if( classPLevel == 1 ) return SLOTS; }
<IN_CLASS>"TQ_CLASSINFO" { X;if( classPLevel == 1 ) return TQ_CLASSINFO; }
<IN_CLASS>"TQ_OBJECT" { X;
if ( classPLevel == 1 )
return TQ_OBJECT;
else if ( classPLevel > 1 )
moc_warn( "Cannot use TQ_OBJECT in nested class." );
}
<IN_CLASS>"TQ_PROPERTY" { X;if( classPLevel == 1 ) return TQ_PROPERTY; }
<IN_CLASS>"TQ_OVERRIDE" { X;if( classPLevel == 1 ) return TQ_OVERRIDE; }
<IN_CLASS>"TQ_ENUMS" { X;if( classPLevel == 1 ) return TQ_ENUMS; }
<IN_CLASS>"TQ_SETS" { X;if( classPLevel == 1 ) return TQ_SETS; }
<IN_NAMESPACE>"{" { namespacePLevel++;Y; }
<IN_NAMESPACE>"}" { namespacePLevel--;Y;if (namespacePLevel == 0)
{X;return '}';}}
<IN_NAMESPACE>"class" { X;
BEGIN QT_DEF;
return CLASS; }
<IN_NAMESPACE>"template" { X;
BEGIN QT_DEF;
return TEMPLATE; }
<IN_NAMESPACE>"namespace" { X;
BEGIN QT_DEF;
return NAMESPACE; }
<IN_NAMESPACE>"using" { X;
BEGIN QT_DEF;
return USING; }
<IN_PROPERTY>"(" { X; return '('; }
<IN_PROPERTY>")" { X; return ')'; }
<IN_PROPERTY>"READ" { X; return READ; }
<IN_PROPERTY>"WRITE" { X; return WRITE; }
<IN_PROPERTY>"STORED" { X; return STORED; }
<IN_PROPERTY>"RESET" { X; return RESET; }
<IN_PROPERTY>"DESIGNABLE" { X; return DESIGNABLE; }
<IN_PROPERTY>"SCRIPTABLE" { X; return SCRIPTABLE; }
<IN_EXPR>"(" { expLevel++;X; }
<IN_EXPR>")" { expLevel--;Y;if (expLevel == 0)
{ X; BEGIN QT_DEF; return ')';} }
<IN_EXPR>"[" { expLevel++;X; }
<IN_EXPR>"]" { expLevel--;X;if (expLevel == 0)
{ X; BEGIN QT_DEF; return ']';} }
<IN_EXPR>"," { if (expLevel == 0)
{ X; BEGIN QT_DEF; return ',' ;} }
<IN_EXPR>";" { if (expLevel == 0)
{ X; BEGIN QT_DEF; return ';' ;} }
<IN_DEF_ARG>"(" { expLevel++;X; }
<IN_DEF_ARG>")" { expLevel--;Y;if (expLevel == 0)
{ X; BEGIN QT_DEF; return ')';} }
<IN_DEF_ARG>"[" { expLevel++;X; }
<IN_DEF_ARG>"]" { expLevel--;X;if (expLevel == 0)
{ X; BEGIN QT_DEF; return ']';} }
<IN_DEF_ARG>"," { if (expLevel <= 1)
{ X; BEGIN QT_DEF; return ',' ;} }
<IN_DEF_ARG>";" { if (expLevel == 0)
{ X; BEGIN QT_DEF; return ';' ;} }
<IN_ENUM>"(" { enumLevel++;X; }
<IN_ENUM>")" { enumLevel--;X; }
<IN_ENUM>"[" { enumLevel++;X; }
<IN_ENUM>"]" { enumLevel--;X }
<IN_ENUM>"," { if (enumLevel == 0)
{ X; BEGIN QT_DEF; return ',' ;} }
<IN_ENUM>";" { if (enumLevel == 0)
{ X; BEGIN QT_DEF; return ';' ;} }
<IN_ENUM>"}" { if (enumLevel == 0)
{ X; BEGIN QT_DEF; return '}' ;} }
<IN_TEMPL_ARGS>[[(<] { templLevel++;
Y;
addExpressionChar( yytext[0] );
}
<IN_TEMPL_ARGS>[])>] { templLevel--;
Y;
if ( templLevel == 0 ) {
X;
BEGIN QT_DEF;
return yytext[0];
} else {
addExpressionChar( yytext[0] );
}
}
<QT_DEF>"friend" { X;return FRIEND; }
<QT_DEF>"typedef" { X;return TYPEDEF; }
<QT_DEF>"auto" { X;return AUTO; }
<QT_DEF>"register" { X;return REGISTER; }
<QT_DEF>"static" { X;return STATIC; }
<QT_DEF>"extern" { X;return EXTERN; }
<QT_DEF>"inline" { X;return INLINE; }
<QT_DEF>"__inline__" { X;return INLINE; }
<QT_DEF>"virtual" { X;return VIRTUAL; }
<QT_DEF>"const" { X;return CONST; }
<QT_DEF>"volatile" { X;return VOLATILE; }
<QT_DEF>"char" { X;return CHAR; }
<QT_DEF>"short" { X;return SHORT; }
<QT_DEF>"int" { X;return INT; }
<QT_DEF>"long" { X;return LONG; }
<QT_DEF>"signed" { X;return SIGNED; }
<QT_DEF>"unsigned" { X;return UNSIGNED; }
<QT_DEF>"float" { X;return FLOAT; }
<QT_DEF>"double" { X;return DOUBLE; }
<QT_DEF>"void" { X;return VOID; }
<QT_DEF>"enum" { X;return ENUM; }
<QT_DEF>"class" { X;return CLASS; }
<QT_DEF>"struct" { X;return STRUCT; }
<QT_DEF>"union" { X;return UNION; }
<QT_DEF>"asm" { X;return ASM; }
<QT_DEF>"private" { X;return PRIVATE; }
<QT_DEF>"protected" { X;return PROTECTED; }
<QT_DEF>"public" { X;return PUBLIC; }
<QT_DEF>"operator" { X;return OPERATOR; }
<QT_DEF>"::" { X;return DBL_COLON; }
<QT_DEF>"..." { X;return TRIPLE_DOT; }
<QT_DEF>"template" { X;return TEMPLATE; }
<QT_DEF>"mutable" { X;return MUTABLE; }
<QT_DEF>"throw" { X;return THROW; }
<QT_DEF>"using" { X;return USING; }
<QT_DEF>"namespace" { X;return NAMESPACE; }
<QT_DEF>[_a-zA-Z][_a-zA-Z0-9]* {
X;
yylval.string = tqstrdup(yytext);
return IDENTIFIER;
}
<IN_PROPERTY>[_a-zA-Z][_a-zA-Z0-9]* {
X;
yylval.string = tqstrdup(yytext);
return IDENTIFIER;
}
<IN_CLASSINFO>"(" { X; return '('; }
<IN_CLASSINFO>")" { X; return ')'; }
<IN_CLASSINFO>"," { X; return ','; }
<IN_CLASSINFO>{ALMOSTSTRING} {
X;
yylval.string = tqstrdup( yytext + 1 );
input(); /* discard the '"' */
return STRING;
}
<OUTSIDE>[_a-zA-Z][_a-zA-Z0-9]* ;
<IN_CLASS>[_a-zA-Z][_a-zA-Z0-9]* ;
<IN_NAMESPACE>[_a-zA-Z][_a-zA-Z0-9]* ;
<OUTSIDE>{STRING} { /* discard strings */
Z;
}
<IN_CLASS>{STRING} { /* discard strings */
Z;
}
<IN_NAMESPACE>{STRING} { /* discard strings */
Z;
}
<IN_FCT>{ALMOSTSTRING} { /* discard strings */
Z;
addExpressionString( yytext );
input(); /* discard the '"' */
}
<IN_TEMPL_ARGS>{ALMOSTSTRING} {
X;
addExpressionString( yytext );
input(); /* discard the '"' */
return STRING;
}
<QT_DEF>{ALMOSTSTRING} {
X;
yylval.string = tqstrdup( yytext + 1 );
input(); /* discard the '"' */
return STRING;
}
<QT_DEF>'.' { X;
yylval.char_val = yytext[1];
return CHAR_VAL;
}
<QT_DEF>'\\a' { X;
yylval.char_val = '\a';
return CHAR_VAL;
}
<QT_DEF>'\\b' { X;
yylval.char_val = '\b';
return CHAR_VAL;
}
<QT_DEF>'\\f' { X;
yylval.char_val = '\f';
return CHAR_VAL;
}
<QT_DEF>'\\n' { X;
yylval.char_val = '\n';
return CHAR_VAL;
}
<QT_DEF>'\\r' { X;
yylval.char_val = '\r';
return CHAR_VAL;
}
<QT_DEF>'\\t' { X;
yylval.char_val = '\t';
return CHAR_VAL;
}
<QT_DEF>'\\v' { X;
yylval.char_val = '\v';
return CHAR_VAL;
}
<QT_DEF>'\\\\' { X;
yylval.char_val = '\\';
return CHAR_VAL;
}
<QT_DEF>'\\?' { X;
yylval.char_val = '\?';
return CHAR_VAL;
}
<QT_DEF>'\\'' { X;
yylval.char_val = '\'';
return CHAR_VAL;
}
<QT_DEF>'\\\"' { X;
yylval.char_val = '\"'; /* " */
return CHAR_VAL;
}
<QT_DEF>'\\0' { X;
yylval.char_val = '\0';
return CHAR_VAL;
}
<QT_DEF>'\\[0-7]+' { X;
yylval.char_val =
(char)strtol( &yytext[1], 0, 8 );
return CHAR_VAL;
}
<QT_DEF>'\\x[0-9a-fA-F]+' { X;
yylval.char_val =
(char)strtol( &yytext[2], 0, 16 );
return CHAR_VAL;
}
<QT_DEF>'\\.' { X;
yylval.char_val = ' ';
return CHAR_VAL;
}
<QT_DEF>[0-9]+ { X;
yylval.int_val = atoi(yytext);
return INT_VAL;
}
<QT_DEF>[0-9]+\.[0-9]* { X;
yylval.double_val = atof(yytext);
return DOUBLE_VAL;
}
<QT_DEF>\.[0-9]+ { X;
yylval.double_val = atof(yytext);
return DOUBLE_VAL;
}
^#define.*\\$ { /* skip multi-line macro-definitions */
int c, c1;
input(); /* Discard the '\n'. */
do {
c1=' ';
while((c = linput()) != '\n' && c != 0) c1=c;
if (c == 0) break;
} while(c1=='\\');
unput(c); /* put back the '\n' or the EOF */
}
^[ \t]*#.* { /* preprocessor commands are skipped */}
"//"[^\n]* { /* C++ comment */
TQCString s = yytext;
if ( s.contains( "MOC_SKIP_BEGIN" ) ) {
skipLevel++;
if ( skipLevel == 1 ) {
lastState = YYSTATE;
BEGIN SKIP;
}
} else
if ( s.contains( "MOC_SKIP_END" ) ) {
if ( skipLevel == 0 ) {
moc_warn(" MOC_SKIP_END without MOC_SKIP_BEGIN");
} else {
skipLevel--;
if ( skipLevel == 0 ) {
BEGIN lastState;
}
}
}
}
"/*" { /* C comment */
int c = ' ';
do {
if ( c!= '*' ) {
while((c = linput()) != '*' && c != 0)
;
}
if (c == 0) break;
} while(((c = linput())) != '/' && c != 0);
if (c == 0)
unput(c);
}
<IN_TEMPL_ARGS>. { addExpressionChar( yytext[0] ); }
<IN_TEMPL_ARGS>[ \t\r\b\f]+ {
/* spaces are important in template args,
e.g. Foo<const int> */
addExpressionChar( yytext[0] ); }
[ \t\r\b\f]+ ;
<IN_CLASS>. ;
<IN_NAMESPACE>. ;
<IN_FCT>. ;
<IN_EXPR>. { addExpressionChar( yytext[0] ); }
<IN_DEF_ARG>. ;
<IN_ENUM>. { addExpressionChar( yytext[0] ); }
<OUTSIDE>. ;
<SKIP>. ;
<QT_DEF>. {
X;
return yytext[0];
}
<GIMME_SEMICOLON>. {
X;
return ';';
}
\n {
lineNo++;
}
%%
#endif // MOC_YACC_CODE
|