2 * Copyright (C) 1999 the Free Software Foundation.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
32 static int parenth_depth = 0;
33 static int before_comment = INITIAL;
34 static gboolean class_after_c = FALSE;
35 static int code_type = CCODE;
38 static char *gtk_doc_func = NULL; /* current gtk-doc func */
39 GHashTable *gtk_doc_hash = NULL;
41 static GString *cbuf = NULL;
44 GList *include_files = NULL;
45 /* 0 no, 1 means yes, 2+ means don't even start looking anymore */
46 static int look_for_includes = 0;
54 cbuf = g_string_new("");
56 cbuf = g_string_assign(cbuf,"");
64 cbuf = g_string_new(s);
66 cbuf = g_string_append(cbuf,s);
71 add_gtk_doc_func(void)
77 gtk_doc_hash = g_hash_table_new(g_str_hash, g_str_equal);
78 g_hash_table_insert(gtk_doc_hash, gtk_doc_func, g_strdup(cbuf->str));
92 %x GTK_DOC_BEFORE_NAME
98 <*>\n { line_no++; REJECT; }
100 <*>MOTHERFUCKER { fprintf(stderr,"You are a bad bad person!\n"); REJECT; }
102 \/\/.*$ { ; /*comment, ignore*/ }
103 <C_CODE>^#[ \t]*include[ \t][<"][^\n">]*[>"] {
104 if(look_for_includes==1) {
107 char *str = g_strdup(yytext);
108 file = strchr(str,'"');
109 if(!file) file = strchr(str,'<');
111 p = strchr(file,'"');
112 if(!p) p = strchr(file,'>');
114 include_files = g_list_prepend(include_files,g_strdup(file));
120 <CLASS_CODE_I>\/\*\*[ \t]*$ {
121 /* eat out gtk doc stuff */
122 BEGIN(GTK_DOC_BEFORE_NAME);
125 <GTK_DOC_BEFORE_NAME>^[ \t]*\*[ \t]*$ {
126 /* empty doc lines */
129 <GTK_DOC_BEFORE_NAME>^[ \t]*\*\ [_a-zA-Z][_a-zA-Z0-9]*:?[ \t]*$ {
132 p = strchr(yytext, '*');
133 g_free(gtk_doc_func);
134 gtk_doc_func = g_strdup(p+2);
135 p = strchr(gtk_doc_func, ':');
137 g_strstrip(gtk_doc_func);
139 <GTK_DOC_BEFORE_NAME>\*\/ {
142 <GTK_DOC_BEFORE_NAME>. {
144 before_comment = CLASS_CODE_I;
146 <GTK_DOC>^[ \t]*\*[ \t]*$ {
147 /* empty doc lines */
150 <GTK_DOC>^[ \t]*\*?\*\/ {
154 <GTK_DOC>^[ \t]*\*\ {
164 before_comment = CLASS_CODE_I;
181 <C_CODE>\/\/.*$ { add_to_cbuf(yytext); /*comment, ignore*/ }
182 <CLASS_CODE>\/\/.*$ { ; /*comment, ignore*/ }
183 <CLASS_CODE_I>\/\/.*$ { ; /*comment, ignore*/ }
184 \/\* {BEGIN(COMMENT); before_comment = INITIAL; }
188 before_comment = C_CODE;
190 <CLASS_CODE>\/\* {BEGIN(COMMENT); before_comment = CLASS_CODE; }
191 <CLASS_CODE_I>\/\* {BEGIN(COMMENT); before_comment = CLASS_CODE_I; }
193 if(before_comment == C_CODE) add_to_cbuf(yytext);
194 BEGIN(before_comment);
197 /* comment, ignore */
198 if(before_comment == C_CODE) add_to_cbuf(yytext);
201 /* comment, ignore */
202 if(before_comment == C_CODE) add_to_cbuf(yytext);
208 class_after_c = FALSE;
211 ccode_line = line_no;
216 class_after_c = FALSE;
219 ccode_line = line_no;
222 ^\%(ht|headertop)\{ {
225 class_after_c = FALSE;
228 ccode_line = line_no;
230 ^\%(ph|privateheader)\{ {
233 class_after_c = FALSE;
236 ccode_line = line_no;
241 class_after_c = FALSE;
244 ccode_line = line_no;
249 class_after_c = FALSE;
252 ccode_line = line_no;
253 if(look_for_includes==0)
260 if(look_for_includes==1)
265 <C_CODE>\'\{\' { add_to_cbuf(yytext); }
266 <C_CODE>\'\\\{\' { add_to_cbuf(yytext); }
267 <C_CODE>\'\}\' { add_to_cbuf(yytext); }
268 <C_CODE>\'\\\}\' { add_to_cbuf(yytext); }
269 <C_CODE>\'\"\' { add_to_cbuf(yytext); }
270 <C_CODE>\'\\\"\' { add_to_cbuf(yytext); }
272 <C_CODE>\\. { add_to_cbuf(yytext); }
274 BEGIN(C_CODE_STRING);
277 <C_CODE_STRING>\\. { add_to_cbuf(yytext); }
282 <C_CODE_STRING>. { add_to_cbuf(yytext); }
283 <C_CODE_STRING>\n { add_to_cbuf(yytext); }
291 if(parenth_depth<0) {
293 } else if(parenth_depth==0 && class_after_c) {
302 <C_CODE>. { add_to_cbuf(yytext); }
303 <C_CODE>\n { add_to_cbuf(yytext); }
306 static int found_classes = 0;
307 look_for_includes = 2;
310 if(++found_classes > 1) {
312 "Only one class per file allowed",
319 ^[ \t]*requires[ \t]+[0-9]+\.[0-9]+\.[0-9]+[\t ]*$ {
320 int maj = 0,min = 0,pl = 0;
321 int rmaj = 0,rmin = 0,rpl = 0;
324 sscanf(VERSION,"%d.%d.%d",&rmaj,&rmin,&rpl);
325 p = strchr(yytext,'r');
326 g_assert(p); /* we MUST have found it */
327 sscanf(p,"requires %d.%d.%d",&maj,&min,&pl);
329 (rmaj == maj && rmin < min) ||
330 (rmaj == maj && rmin == min && rpl < pl)) {
333 "GOB version %d.%d.%d required "
335 "To upgrade your gob, see: "
336 "http://www.5z.com/jirka/gob.html",
338 print_error(FALSE, s, line_no);
343 <CLASS_CODE,CLASS_CODE_I>class|this {
346 s = g_strdup_printf("'%s' keyword should not "
347 "be used when generating "
349 print_error(TRUE, s, line_no);
355 <CLASS_CODE>from {return FROM;}
357 <CLASS_CODE_I>void {return VOID;}
358 <CLASS_CODE_I>struct {return STRUCT;}
359 <CLASS_CODE_I>union {return UNION;}
360 <CLASS_CODE_I>enum {return ENUM;}
361 <CLASS_CODE_I>signed {return SIGNED;}
362 <CLASS_CODE_I>unsigned {return UNSIGNED;}
363 <CLASS_CODE_I>long {return LONG;}
364 <CLASS_CODE_I>short {return SHORT;}
365 <CLASS_CODE_I>int {return INT;}
366 <CLASS_CODE_I>float {return FLOAT;}
367 <CLASS_CODE_I>double {return DOUBLE;}
368 <CLASS_CODE_I>char {return CHAR;}
369 <CLASS_CODE_I>const {return CONST;}
371 <CLASS_CODE_I>\.\.\. {return THREEDOTS;}
373 <CLASS_CODE_I>public {yylval.line = line_no; return PUBLIC;}
374 <CLASS_CODE_I>private {yylval.line = line_no; return PRIVATE;}
375 <CLASS_CODE_I>protected {yylval.line = line_no; return PROTECTED;}
376 <CLASS_CODE_I>argument {yylval.line = line_no; return ARGUMENT;}
377 <CLASS_CODE_I>virtual {yylval.line = line_no; return VIRTUAL;}
378 <CLASS_CODE_I>signal {yylval.line = line_no; return SIGNAL;}
379 <CLASS_CODE_I>override {yylval.line = line_no; return OVERRIDE;}
380 <CLASS_CODE_I>onerror {return ONERROR;}
381 <CLASS_CODE_I>0|[1-9][0-9]*|0x[0-9a-fA-F]+|0[0-7]+|[0-9]*\.[0-9]+|\.[0-9][0-9]* {
382 yylval.id = g_strdup(yytext);
385 <CLASS_CODE,CLASS_CODE_I>[A-Za-z_][A-Za-z0-9_]*(:[A-Za-z0-9_]*)+ {
386 /* this one is for a classname with a namespace */
387 yylval.id = g_strdup(yytext);
390 <CLASS_CODE,CLASS_CODE_I>:[A-Za-z_][A-Za-z0-9_]*(:[A-Za-z0-9_]*)* {
391 /* this is for a classname with an empty namespace */
392 yylval.id = g_strdup(yytext);
395 <CLASS_CODE,CLASS_CODE_I>[A-Za-z_][A-Za-z0-9_]* {
396 yylval.id = g_strdup(yytext);
400 <CLASS_CODE_I>(\[[0-9]*\])+ {
401 yylval.id = g_strdup(yytext);
412 class_after_c = TRUE;
413 yylval.line = line_no;
415 ccode_line = line_no;
423 <CLASS_CODE,CLASS_CODE_I,INITIAL>[\t ] ; /*ignore*/
426 yylval.line = line_no;
430 <*>[\n\r] ; /*ignore*/