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,
31 static int parenth_depth = 0;
32 static int before_comment = INITIAL;
33 static gboolean class_after_c = FALSE;
34 static int code_type = CCODE;
37 static char *gtk_doc_func = NULL; /* current gtk-doc func */
38 GHashTable *gtk_doc_hash = NULL;
40 static GString *cbuf = NULL;
43 GList *include_files = NULL;
44 /* 0 no, 1 means yes, 2+ means don't even start looking anymore */
45 static int look_for_includes = 0;
53 cbuf = g_string_new("");
55 cbuf = g_string_assign(cbuf,"");
63 cbuf = g_string_new(s);
65 cbuf = g_string_append(cbuf,s);
70 add_gtk_doc_func(void)
76 gtk_doc_hash = g_hash_table_new(g_str_hash, g_str_equal);
77 g_hash_table_insert(gtk_doc_hash, gtk_doc_func, g_strdup(cbuf->str));
91 %x GTK_DOC_BEFORE_NAME
97 <*>\n { line_no++; REJECT; }
99 <*>MOTHERFUCKER { fprintf(stderr,"You are a bad bad person!\n"); REJECT; }
101 \/\/.*$ { ; /*comment, ignore*/ }
102 <C_CODE>^#[ \t]*include[ \t][<"][^\n">]*[>"] {
103 if(look_for_includes==1) {
106 char *str = g_strdup(yytext);
107 file = strchr(str,'"');
108 if(!file) file = strchr(str,'<');
110 p = strchr(file,'"');
111 if(!p) p = strchr(file,'>');
113 include_files = g_list_prepend(include_files,g_strdup(file));
119 <CLASS_CODE_I>\/\*\*[ \t]*$ {
120 /* eat out gtk doc stuff */
121 BEGIN(GTK_DOC_BEFORE_NAME);
124 <GTK_DOC_BEFORE_NAME>^[ \t]*\*[ \t]*$ {
125 /* empty doc lines */
128 <GTK_DOC_BEFORE_NAME>^[ \t]*\*\ [_a-zA-Z][_a-zA-Z0-9]*:?[ \t]*$ {
131 p = strchr(yytext, '*');
132 g_free(gtk_doc_func);
133 gtk_doc_func = g_strdup(p+2);
134 p = strchr(gtk_doc_func, ':');
136 g_strstrip(gtk_doc_func);
138 <GTK_DOC_BEFORE_NAME>\*\/ {
141 <GTK_DOC_BEFORE_NAME>. {
143 before_comment = CLASS_CODE_I;
145 <GTK_DOC>^[ \t]*\*[ \t]*$ {
146 /* empty doc lines */
149 <GTK_DOC>^[ \t]*\*?\*\/ {
153 <GTK_DOC>^[ \t]*\*\ {
163 before_comment = CLASS_CODE_I;
180 <C_CODE>\/\/.*$ { add_to_cbuf(yytext); /*comment, ignore*/ }
181 <CLASS_CODE>\/\/.*$ { ; /*comment, ignore*/ }
182 <CLASS_CODE_I>\/\/.*$ { ; /*comment, ignore*/ }
183 \/\* {BEGIN(COMMENT); before_comment = INITIAL; }
187 before_comment = C_CODE;
189 <CLASS_CODE>\/\* {BEGIN(COMMENT); before_comment = CLASS_CODE; }
190 <CLASS_CODE_I>\/\* {BEGIN(COMMENT); before_comment = CLASS_CODE_I; }
192 if(before_comment == C_CODE) add_to_cbuf(yytext);
193 BEGIN(before_comment);
196 /* comment, ignore */
197 if(before_comment == C_CODE) add_to_cbuf(yytext);
200 /* comment, ignore */
201 if(before_comment == C_CODE) add_to_cbuf(yytext);
207 class_after_c = FALSE;
210 ccode_line = line_no;
215 class_after_c = FALSE;
218 ccode_line = line_no;
221 ^\%(ht|headertop)\{ {
224 class_after_c = FALSE;
227 ccode_line = line_no;
229 ^\%(ph|privateheader)\{ {
232 class_after_c = FALSE;
235 ccode_line = line_no;
240 class_after_c = FALSE;
243 ccode_line = line_no;
248 class_after_c = FALSE;
251 ccode_line = line_no;
252 if(look_for_includes==0)
259 if(look_for_includes==1)
264 <C_CODE>\'\{\' { add_to_cbuf(yytext); }
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); }
271 <C_CODE>\\. { add_to_cbuf(yytext); }
273 BEGIN(C_CODE_STRING);
276 <C_CODE_STRING>\\. { add_to_cbuf(yytext); }
281 <C_CODE_STRING>. { add_to_cbuf(yytext); }
282 <C_CODE_STRING>\n { add_to_cbuf(yytext); }
290 if(parenth_depth<0) {
292 } else if(parenth_depth==0 && class_after_c) {
301 <C_CODE>. { add_to_cbuf(yytext); }
302 <C_CODE>\n { add_to_cbuf(yytext); }
305 static int found_classes = 0;
306 look_for_includes = 2;
309 if(++found_classes > 1) {
311 "Only one class per file allowed",
318 ^[ \t]*requires[ \t]+[0-9]+\.[0-9]+\.[0-9]+[\t ]*$ {
319 int maj = 0,min = 0,pl = 0;
320 int rmaj = 0,rmin = 0,rpl = 0;
323 sscanf(VERSION,"%d.%d.%d",&rmaj,&rmin,&rpl);
324 p = strchr(yytext,'r');
325 g_assert(p); /* we MUST have found it */
326 sscanf(p,"requires %d.%d.%d",&maj,&min,&pl);
328 (rmaj == maj && rmin < min) ||
329 (rmaj == maj && rmin == min && rpl < pl)) {
332 "GOB version %d.%d.%d required "
334 "To upgrade your gob, see: "
335 "http://www.5z.com/jirka/gob.html",
337 print_error(FALSE, s, line_no);
342 <CLASS_CODE,CLASS_CODE_I>class|this {
345 s = g_strdup_printf("'%s' keyword should not "
346 "be used when generating "
348 print_error(TRUE, s, line_no);
354 <CLASS_CODE>from {return FROM;}
356 <CLASS_CODE_I>void {return VOID;}
357 <CLASS_CODE_I>struct {return STRUCT;}
358 <CLASS_CODE_I>union {return UNION;}
359 <CLASS_CODE_I>enum {return ENUM;}
360 <CLASS_CODE_I>signed {return SIGNED;}
361 <CLASS_CODE_I>unsigned {return UNSIGNED;}
362 <CLASS_CODE_I>long {return LONG;}
363 <CLASS_CODE_I>short {return SHORT;}
364 <CLASS_CODE_I>int {return INT;}
365 <CLASS_CODE_I>float {return FLOAT;}
366 <CLASS_CODE_I>double {return DOUBLE;}
367 <CLASS_CODE_I>char {return CHAR;}
368 <CLASS_CODE_I>const {return CONST;}
370 <CLASS_CODE_I>\.\.\. {return THREEDOTS;}
372 <CLASS_CODE_I>public {yylval.line = line_no; return PUBLIC;}
373 <CLASS_CODE_I>private {yylval.line = line_no; return PRIVATE;}
374 <CLASS_CODE_I>protected {yylval.line = line_no; return PROTECTED;}
375 <CLASS_CODE_I>argument {yylval.line = line_no; return ARGUMENT;}
376 <CLASS_CODE_I>virtual {yylval.line = line_no; return VIRTUAL;}
377 <CLASS_CODE_I>signal {yylval.line = line_no; return SIGNAL;}
378 <CLASS_CODE_I>override {yylval.line = line_no; return OVERRIDE;}
379 <CLASS_CODE_I>onerror {return ONERROR;}
380 <CLASS_CODE_I>0|[1-9][0-9]*|0x[0-9a-fA-F]+|0[0-7]+|[0-9]*\.[0-9]+|\.[0-9][0-9]* {
381 yylval.id = g_strdup(yytext);
384 <CLASS_CODE,CLASS_CODE_I>:?[A-Za-z_][A-Za-z0-9_]*(:[A-Za-z0-9_]*)+ {
385 yylval.id = g_strdup(yytext);
388 <CLASS_CODE,CLASS_CODE_I>[A-Za-z_][A-Za-z0-9_]* {
389 yylval.id = g_strdup(yytext);
393 <CLASS_CODE_I>(\[[0-9]*\])+ {
394 yylval.id = g_strdup(yytext);
405 class_after_c = TRUE;
406 yylval.line = line_no;
408 ccode_line = line_no;
416 <CLASS_CODE,CLASS_CODE_I,INITIAL>[\t ] ; /*ignore*/
419 yylval.line = line_no;
423 <*>[\n\r] ; /*ignore*/