]> git.draconx.ca Git - gob-dx.git/blobdiff - src/lexer.l
Release 0.92.3
[gob-dx.git] / src / lexer.l
index d896eb2f4b504e997ae87ab60081eb68b1da441c..68bafd020eba981874ce6b990a026989742eb1cd 100644 (file)
@@ -33,6 +33,10 @@ static int before_comment = INITIAL;
 static gboolean class_after_c = FALSE;
 static int code_type = CCODE;
 
+/* GTK+ doc stuff */
+static char *gtk_doc_func = NULL; /* current gtk-doc func */
+GHashTable *gtk_doc_hash = NULL;
+
 static GString *cbuf = NULL;
 int ccode_line = 1;
 
@@ -62,6 +66,21 @@ add_to_cbuf(char *s)
        }
 }
 
+static void
+add_gtk_doc_func(void)
+{
+       if(!gtk_doc_func)
+               return;
+
+       if(!gtk_doc_hash)
+               gtk_doc_hash = g_hash_table_new(g_str_hash, g_str_equal);
+       g_hash_table_insert(gtk_doc_hash, gtk_doc_func, g_strdup(cbuf->str));
+       clear_cbuf();
+
+       gtk_doc_func = NULL;
+}
+
+
 %}
 
 %x COMMENT
@@ -69,6 +88,9 @@ add_to_cbuf(char *s)
 %x C_CODE_STRING
 %x CLASS_CODE
 %x CLASS_CODE_I
+%x GTK_DOC_BEFORE_NAME
+%x GTK_DOC
+%x GTK_DOC_LINE
 
 %%
 
@@ -94,6 +116,67 @@ add_to_cbuf(char *s)
        REJECT;
 }
 
+<CLASS_CODE_I>\/\*\*[ \t]*$    {
+                       /* eat out gtk doc stuff */
+                       BEGIN(GTK_DOC_BEFORE_NAME);
+                       clear_cbuf();
+               }
+<GTK_DOC_BEFORE_NAME>^[ \t]*\*[ \t]*$  {
+                       /* empty doc lines */
+                       ;
+               }       
+<GTK_DOC_BEFORE_NAME>^[ \t]*\*\ [_a-zA-Z][_a-zA-Z0-9]*:?[ \t]*$        {
+                       char *p;
+                       BEGIN(GTK_DOC);
+                       p = strchr(yytext, '*');
+                       g_free(gtk_doc_func);
+                       gtk_doc_func = g_strdup(p+2);
+                       p = strchr(gtk_doc_func, ':');
+                       if(p) *p='\0';
+                       g_strstrip(gtk_doc_func);
+               }
+<GTK_DOC_BEFORE_NAME>\*\/      {
+                       BEGIN(CLASS_CODE_I);
+               }
+<GTK_DOC_BEFORE_NAME>. {
+                       BEGIN(COMMENT);
+                       before_comment = CLASS_CODE_I;
+               }
+<GTK_DOC>^[ \t]*\*[ \t]*$      {
+                       /* empty doc lines */
+                       add_to_cbuf(" *\n");
+               }       
+<GTK_DOC>^[ \t]*\*?\*\/        {
+                       BEGIN(CLASS_CODE_I);
+                       add_gtk_doc_func();
+               }
+<GTK_DOC>^[ \t]*\*\    {
+                       fflush(stdout);
+                       add_to_cbuf(" * ");
+                       BEGIN(GTK_DOC_LINE);
+               }
+<GTK_DOC>\*\/  {
+                       BEGIN(CLASS_CODE_I);
+               }
+<GTK_DOC>.     {
+                       BEGIN(COMMENT);
+                       before_comment = CLASS_CODE_I;
+               }
+<GTK_DOC_LINE>\*\/     {
+                       BEGIN(CLASS_CODE_I);
+                       add_to_cbuf("\n");
+                       add_gtk_doc_func();
+               }
+<GTK_DOC_LINE>.$       {
+                       BEGIN(GTK_DOC);
+                       add_to_cbuf(yytext);
+                       add_to_cbuf("\n");
+               }
+<GTK_DOC_LINE>.        {
+                       fflush(stdout);
+                       add_to_cbuf(yytext);
+               }
+
 <C_CODE>\/\/.*$                { add_to_cbuf(yytext); /*comment, ignore*/ }
 <CLASS_CODE>\/\/.*$    { ; /*comment, ignore*/ }
 <CLASS_CODE_I>\/\/.*$  { ; /*comment, ignore*/ }
@@ -202,8 +285,16 @@ add_to_cbuf(char *s)
 <C_CODE>\n     { add_to_cbuf(yytext); }
 
 class          {
+                       static int found_classes = 0;
                        look_for_includes = 2;
                        BEGIN(CLASS_CODE);
+
+                       if(++found_classes > 1) {
+                               print_error(FALSE, 
+                                           "Only one class per file allowed",
+                                           line_no);
+                       }
+
                        return CLASS;
                }
 
@@ -226,7 +317,7 @@ class               {
                                    "To upgrade your gob, see: "
                                    "http://www.5z.com/jirka/gob.html",
                                    maj,min,pl,VERSION);
-                               print_error(FALSE,s, line_no);
+                               print_error(FALSE, s, line_no);
                                g_free(s);
                        }
                }
@@ -237,7 +328,7 @@ class               {
                                s = g_strdup_printf("'%s' keyword should not "
                                                    "be used when generating "
                                                    "C++ code",yytext);
-                               print_error(TRUE,s, line_no);
+                               print_error(TRUE, s, line_no);
                                g_free(s);
                        }
                        REJECT;