]> git.draconx.ca Git - gob-dx.git/blobdiff - src/lexer.l
Release 1.99.2
[gob-dx.git] / src / lexer.l
index e102286510e0a8c4c4d993e78f9b48ca69ba5d80..08326211214b03f1e41a212a8f2b28bc13625b26 100644 (file)
@@ -23,6 +23,7 @@
 #include "config.h"
 #include <glib.h>
 #include <string.h>
+#include <ctype.h>
 
 #include "treefuncs.h"
 #include "parse.h"
@@ -48,6 +49,8 @@ GList *include_files = NULL;
 static int look_for_includes = 0;
 
 int line_no = 1;
+/* last filename parsed from a #line directive */
+char *hline_filename = NULL;
 
 static void
 clear_cbuf(void)
@@ -138,6 +141,44 @@ REJECT;
 }
 
 \/\/.*$                        { ; /*comment, ignore*/ }
+
+<*>^#[ \t]*line[ \t]+[0-9]+([ \t]\"[^\n\r\f\"]*\")? {
+       char *p;
+       char *number;
+       char *filename;
+       char *str=g_strdup(yytext);
+
+       /* find first digit of line number */
+       p=str;
+       while(*p&&!isdigit(*p)) p++;
+       number=p;
+  
+       /* find end of line number */
+       while(*p&&isdigit(*p)) p++;
+       if(*p) *p++=0;
+
+       /* find beginning of filename */
+       p=strchr(p,'"');
+       if(p) p++;
+       filename=p;
+
+       /* find end of filename */
+       if(p) p=strchr(p,'"');
+       if(p) *p=0;
+
+       /* stash number (minus one because we don't count this line) */  
+       if(number) line_no=atoi(number)-1;
+
+       /* stash filename */
+       if(filename) {
+               if(hline_filename) g_free(hline_filename);
+               hline_filename=g_strdup(filename);
+       }
+  
+       /* clean up */
+       g_free(str);
+}
+
 <C_CODE>^#[ \t]*include[ \t][<"][^\n">]*[>"] {
        if(look_for_includes==1) {
                char *p;
@@ -367,6 +408,10 @@ class              {
                        return CLASS;
                }
 
+error          { return ERROR; }
+enum           { return ENUM; }
+flags          { return FLAGS; }
+
 ^[ \t]*requires[ \t]+[0-9]+\.[0-9]+\.[0-9]+[\t ]*$     {
                        int maj = 0, min = 0, pl = 0;
                        int rmaj = 0, rmin = 0, rpl = 0;
@@ -403,7 +448,7 @@ class               {
                                             "(this is %s)\n"
                                             "To upgrade your gob, see: "
                                             "http://www.5z.com/jirka/gob.html",
-                                            maj, VERSION);
+                                            effective_maj, VERSION);
                        }
 
                }
@@ -481,25 +526,25 @@ class             {
                return ')';
                        }
 
-<CLASS_CODE,CLASS_CODE_I,PROPERTY_CODE,PROPERTY_CODE_I>0|[1-9][0-9]*|0x[0-9a-fA-F]+|0[0-7]+|[0-9]*\.[0-9]+|\.[0-9][0-9]*       {
+<CLASS_CODE,CLASS_CODE_I,PROPERTY_CODE,PROPERTY_CODE_I,INITIAL>0|[1-9][0-9]*|0x[0-9a-fA-F]+|0[0-7]+|[0-9]*\.[0-9]+|\.[0-9][0-9]*       {
                        yylval.id = g_strdup(yytext);
                        return NUMBER;
                }
-<CLASS_CODE,CLASS_CODE_I,PROPERTY_CODE,PROPERTY_CODE_I>[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-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>:[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-z0-9_]*)*        {
                        /* this is for a classname with an empty namespace */
                        yylval.id = g_strdup(yytext);
                        return TYPETOKEN;
                }
-<CLASS_CODE,CLASS_CODE_I,PROPERTY_CODE,PROPERTY_CODE_I>[A-Za-z_][A-Za-z0-9_]*  {
+<CLASS_CODE,CLASS_CODE_I,PROPERTY_CODE,PROPERTY_CODE_I,INITIAL>[A-Za-z_][A-Za-z0-9_]*  {
                        yylval.id = g_strdup(yytext);
                        return TOKEN;
                }
-<CLASS_CODE,CLASS_CODE_I,PROPERTY_CODE,PROPERTY_CODE_I>\'\\.\'|\'.\'   {
+<CLASS_CODE,CLASS_CODE_I,PROPERTY_CODE,PROPERTY_CODE_I,INITIAL>\'\\.\'|\'.\'   {
                        yylval.id = g_strdup(yytext);
                        return SINGLE_CHAR;
                }
@@ -527,7 +572,7 @@ class               {
                                return '}';
                        }
 
-<CLASS_CODE,CLASS_CODE_I,INITIAL,PROPERTY_CODE,PROPERTY_CODE_I>[\t ]   ;  /*ignore*/
+<CLASS_CODE,CLASS_CODE_I,INITIAL,PROPERTY_CODE,PROPERTY_CODE_I>[\f\t ] ;  /*ignore*/
 
 <*>.           {
                        yylval.line = line_no;