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);
204 ^\%(ht|headertop)\{ {
207 class_after_c = FALSE;
210 ccode_line = line_no;
212 ^\%(ph|privateheader)\{ {
215 class_after_c = FALSE;
218 ccode_line = line_no;
223 class_after_c = FALSE;
226 ccode_line = line_no;
231 class_after_c = FALSE;
234 ccode_line = line_no;
235 if(look_for_includes==0)
242 if(look_for_includes==1)
247 <C_CODE>\'\{\' { add_to_cbuf(yytext); }
248 <C_CODE>\'\\\{\' { add_to_cbuf(yytext); }
249 <C_CODE>\'\}\' { add_to_cbuf(yytext); }
250 <C_CODE>\'\\\}\' { add_to_cbuf(yytext); }
251 <C_CODE>\'\"\' { add_to_cbuf(yytext); }
252 <C_CODE>\'\\\"\' { add_to_cbuf(yytext); }
254 <C_CODE>\\. { add_to_cbuf(yytext); }
256 BEGIN(C_CODE_STRING);
259 <C_CODE_STRING>\\. { add_to_cbuf(yytext); }
264 <C_CODE_STRING>. { add_to_cbuf(yytext); }
265 <C_CODE_STRING>\n { add_to_cbuf(yytext); }
273 if(parenth_depth<0) {
275 } else if(parenth_depth==0 && class_after_c) {
284 <C_CODE>. { add_to_cbuf(yytext); }
285 <C_CODE>\n { add_to_cbuf(yytext); }
288 static int found_classes = 0;
289 look_for_includes = 2;
292 if(++found_classes > 1) {
294 "Only one class per file allowed",
301 ^[ \t]*requires[ \t]+[0-9]+\.[0-9]+\.[0-9]+[\t ]*$ {
302 int maj = 0,min = 0,pl = 0;
303 int rmaj = 0,rmin = 0,rpl = 0;
306 sscanf(VERSION,"%d.%d.%d",&rmaj,&rmin,&rpl);
307 p = strchr(yytext,'r');
308 g_assert(p); /* we MUST have found it */
309 sscanf(p,"requires %d.%d.%d",&maj,&min,&pl);
311 (rmaj == maj && rmin < min) ||
312 (rmaj == maj && rmin == min && rpl < pl)) {
315 "GOB version %d.%d.%d required "
317 "To upgrade your gob, see: "
318 "http://www.5z.com/jirka/gob.html",
320 print_error(FALSE, s, line_no);
325 <CLASS_CODE,CLASS_CODE_I>class|this {
328 s = g_strdup_printf("'%s' keyword should not "
329 "be used when generating "
331 print_error(TRUE, s, line_no);
337 <CLASS_CODE>from {return FROM;}
339 <CLASS_CODE_I>void {return VOID;}
340 <CLASS_CODE_I>struct {return STRUCT;}
341 <CLASS_CODE_I>union {return UNION;}
342 <CLASS_CODE_I>enum {return ENUM;}
343 <CLASS_CODE_I>signed {return SIGNED;}
344 <CLASS_CODE_I>unsigned {return UNSIGNED;}
345 <CLASS_CODE_I>long {return LONG;}
346 <CLASS_CODE_I>short {return SHORT;}
347 <CLASS_CODE_I>int {return INT;}
348 <CLASS_CODE_I>float {return FLOAT;}
349 <CLASS_CODE_I>double {return DOUBLE;}
350 <CLASS_CODE_I>char {return CHAR;}
351 <CLASS_CODE_I>const {return CONST;}
353 <CLASS_CODE_I>\.\.\. {return THREEDOTS;}
355 <CLASS_CODE_I>public {yylval.line = line_no; return PUBLIC;}
356 <CLASS_CODE_I>private {yylval.line = line_no; return PRIVATE;}
357 <CLASS_CODE_I>protected {yylval.line = line_no; return PROTECTED;}
358 <CLASS_CODE_I>argument {yylval.line = line_no; return ARGUMENT;}
359 <CLASS_CODE_I>virtual {yylval.line = line_no; return VIRTUAL;}
360 <CLASS_CODE_I>signal {yylval.line = line_no; return SIGNAL;}
361 <CLASS_CODE_I>override {yylval.line = line_no; return OVERRIDE;}
362 <CLASS_CODE_I>onerror {return ONERROR;}
363 <CLASS_CODE_I>0|[1-9][0-9]*|0x[0-9a-fA-F]+|0[0-7]+|[0-9]*\.[0-9]+|\.[0-9][0-9]* {
364 yylval.id = g_strdup(yytext);
367 <CLASS_CODE,CLASS_CODE_I>:?[A-Za-z_][A-Za-z0-9_]*(:[A-Za-z0-9_]*)+ {
368 yylval.id = g_strdup(yytext);
371 <CLASS_CODE,CLASS_CODE_I>[A-Za-z_][A-Za-z0-9_]* {
372 yylval.id = g_strdup(yytext);
376 <CLASS_CODE_I>(\[[0-9]*\])+ {
377 yylval.id = g_strdup(yytext);
388 class_after_c = TRUE;
389 yylval.line = line_no;
391 ccode_line = line_no;
399 <CLASS_CODE,CLASS_CODE_I,INITIAL>[\t ] ; /*ignore*/
402 yylval.line = line_no;
406 <*>[\n\r] ; /*ignore*/