]> git.draconx.ca Git - gob-dx.git/blobdiff - src/lexer.l
Rename "prealloc" global variable.
[gob-dx.git] / src / lexer.l
index b48e818d030e0dc5ba3c88a88b023deda9f6d7bc..d33965db2119190c474205bc44ddaafbb210bff8 100644 (file)
@@ -1,5 +1,9 @@
-/* GOB C Preprocessor
- * Copyright (C) 1999 the Free Software Foundation.
+%top{
+/*
+ * GOB C Preprocessor
+ * Copyright (C) 1999-2000 the Free Software Foundation.
+ * Copyright (C) 2000 Eazel, Inc.
+ * Copyright (C) 2001-2011 George (Jiri) Lebl
  *
  * Author: George Lebl
  *
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  * USA.
  */
-%{
+#include <config.h>
+}
 
-#include "config.h"
-#include <glib.h>
+%{
+#include <stdlib.h>
 #include <string.h>
 #include <ctype.h>
+#include <glib.h>
 
 #include "treefuncs.h"
 #include "parse.h"
@@ -92,9 +98,10 @@ add_gtk_doc_func(void)
        gtk_doc_func = NULL;
 }
 
-/* Ugly warning avoiding */
+/* Ugly warning / error avoidings */
 #ifdef FLEX_SCANNER
 int yylex(void);
+int yywrap(void) { return 1; }
 #endif
 
 %}
@@ -103,6 +110,7 @@ int yylex(void);
 %x C_CODE
 %x CODE_STRING
 %x CLASS_CODE
+%x CLASS_STRING
 %x CLASS_CODE_I
 %x PROPERTY_CODE
 %x PROPERTY_CODE_I
@@ -185,7 +193,7 @@ REJECT;
        g_free(str);
 }
 
-<C_CODE>^#[ \t]*include[ \t][<"][^\n">]*[>"] {
+<C_CODE>^#[ \t]*include[ \t][<"][^\n\r">]*[>"] {
        if(look_for_includes==1) {
                char *p;
                char *file;
@@ -195,9 +203,11 @@ REJECT;
                file++;
                p = strchr(file,'"');
                if(!p) p = strchr(file,'>');
-               *p = '\0';
-               include_files = g_list_prepend(include_files,g_strdup(file));
-               g_free(str);
+               if (p != NULL) {
+                       *p = '\0';
+                       include_files = g_list_prepend(include_files,g_strdup(file));
+                       g_free(str);
+               }
        }
        REJECT;
 }
@@ -340,6 +350,24 @@ REJECT;
                        if(look_for_includes==0)
                                look_for_includes=1;
                }
+^\%(ct|ctop)\{         {
+                       BEGIN(C_CODE);
+                       parenth_depth = 1;
+                       class_after_c = FALSE;
+                       code_type = CTCODE;
+                       clear_cbuf();
+                       ccode_line = line_no;
+                       if(look_for_includes==0)
+                               look_for_includes=1;
+               }
+^\%(ad|afterdecls)\{           {
+                       BEGIN(C_CODE);
+                       parenth_depth = 1;
+                       class_after_c = FALSE;
+                       code_type = ADCODE;
+                       clear_cbuf();
+                       ccode_line = line_no;
+               }
 <C_CODE>^\%\}  {
                        BEGIN(INITIAL);
                        yylval.cbuf = cbuf;
@@ -472,6 +500,28 @@ flags              { return FLAGS; }
                }
 
 <CLASS_CODE>from       {return FROM;}
+<CLASS_CODE>\" {
+                       BEGIN(CLASS_STRING);
+                       before_string = CLASS_CODE;
+                       add_to_cbuf(yytext);
+               }
+<CLASS_STRING>\\.      { add_to_cbuf(yytext); }
+<CLASS_STRING>\"       {
+                       BEGIN(before_string);
+                       add_to_cbuf(yytext);
+                       yylval.id = cbuf->str;
+                       g_string_free (cbuf, FALSE);
+                       cbuf = NULL;
+                       return STRING;
+               }
+<CLASS_STRING>.        { add_to_cbuf(yytext); }
+<CLASS_STRING>\n       { add_to_cbuf(yytext); }
+
+<CLASS_CODE_I>\"       {
+                       BEGIN(CLASS_STRING);
+                       before_string = CLASS_CODE_I;
+                       add_to_cbuf(yytext);
+               }
 
 <CLASS_CODE_I,PROPERTY_CODE_I>void     {return VOID;}
 <CLASS_CODE_I,PROPERTY_CODE_I>struct   {return STRUCT;}
@@ -503,6 +553,7 @@ flags               { return FLAGS; }
                                return PROPERTY;
                        }
 <PROPERTY_CODE_I>nick  { yylval.line = line_no; return NICK; }
+<PROPERTY_CODE_I>name  { yylval.line = line_no; return NAME; }
 <PROPERTY_CODE_I>blurb { yylval.line = line_no; return BLURB; }
 <PROPERTY_CODE_I>maximum       { yylval.line = line_no; return MAXIMUM; }
 <PROPERTY_CODE_I>minimum       { yylval.line = line_no; return MINIMUM; }
@@ -547,12 +598,12 @@ flags             { return FLAGS; }
                                REJECT;
                        }
                }
-<CLASS_CODE,CLASS_CODE_I,PROPERTY_CODE,PROPERTY_CODE_I,INITIAL>[A-Za-z_][A-Za-z0-9_]*(:[A-Za-z0-9_]*)+ {
+<CLASS_CODE,CLASS_CODE_I,PROPERTY_CODE,PROPERTY_CODE_I,INITIAL>[A-Za-z_][A-Za-z0-9_]*(:[A-Za-z_][A-Za-z0-9_]*)+        {
                        /* this one is for a classname with a namespace */
                        yylval.id = g_strdup(yytext);
                        return TYPETOKEN;
                }
-<CLASS_CODE,CLASS_CODE_I,PROPERTY_CODE,PROPERTY_CODE_I,INITIAL>:[A-Za-z_][A-Za-z0-9_]*(:[A-Za-z0-9_]*)*        {
+<CLASS_CODE,CLASS_CODE_I,PROPERTY_CODE,PROPERTY_CODE_I,INITIAL>:[A-Za-z_][A-Za-z0-9_]*(:[A-Za-z_][A-Za-z0-9_]*)*       {
                        /* this is for a classname with an empty namespace */
                        yylval.id = g_strdup(yytext);
                        return TYPETOKEN;
@@ -570,12 +621,16 @@ flags             { return FLAGS; }
                        yylval.id = g_strdup(yytext);
                        return ARRAY_DIM;
                }
-
+<CLASS_CODE_I>:[0-9]+ {
+                       /* cheat for bitfield */
+                       yylval.id = g_strdup(yytext);
+                       return ARRAY_DIM;
+               }
 <CLASS_CODE>\{ {
                        BEGIN(CLASS_CODE_I);
                        return '{';
                }
-<CLASS_CODE_I>\{       {
+<CLASS_CODE_I,PROPERTY_CODE>\{ {
                        BEGIN(C_CODE);
                        parenth_depth=1;
                        class_after_c = TRUE;
@@ -591,11 +646,21 @@ flags             { return FLAGS; }
 
 <CLASS_CODE,CLASS_CODE_I,INITIAL,PROPERTY_CODE,PROPERTY_CODE_I>[\f\t ] ;  /*ignore*/
 
+<*>[\n\r]      ;  /*ignore*/
+
+
 <*>.           {
                        yylval.line = line_no;
                        return yytext[0];
                }
 
-<*>[\n\r]      ;  /*ignore*/
+^[ \t]*prealloc[ \t]+[0-9]+[ \t]*$ {
+                       char *p;
+                       int t;
+                       p = strchr (yytext,'p');
+                       g_assert (p); /* we MUST have found it */
+                       sscanf (p, "prealloc %d", &t);
+                       npreallocs=t;
+               }
 
 %%