]> git.draconx.ca Git - gob-dx.git/blobdiff - src/lexer.l
Release 1.0.12
[gob-dx.git] / src / lexer.l
index a33eed0a7720e3a7113830fbc7f8413499e0b49d..37ec65a0ce0aac6b230d5c87cc605b456d7f9859 100644 (file)
@@ -23,6 +23,7 @@
 #include "config.h"
 #include <glib.h>
 #include <string.h>
+#include <ctype.h>
 
 #include "treefuncs.h"
 #include "parse.h"
@@ -46,6 +47,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)
@@ -126,6 +129,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;
@@ -334,9 +375,8 @@ class               {
                        BEGIN(CLASS_CODE);
 
                        if(++found_classes > 1) {
-                               print_error(FALSE, 
-                                           "Only one class per file allowed",
-                                           line_no);
+                               error_print(GOB_ERROR, line_no,
+                                           "Only one class per file allowed");
                        }
 
                        return CLASS;
@@ -345,35 +385,49 @@ class             {
 ^[ \t]*requires[ \t]+[0-9]+\.[0-9]+\.[0-9]+[\t ]*$     {
                        int maj = 0,min = 0,pl = 0;
                        int rmaj = 0,rmin = 0,rpl = 0;
+                       int effective_maj = 0;
+                       int effective_rmaj = 0;
                        char *p;
                        
                        sscanf(VERSION,"%d.%d.%d",&rmaj,&rmin,&rpl);
+                       effective_rmaj = rmaj;
+                       if (rmin >= 90)
+                               effective_rmaj = rmaj + 1;
+
                        p = strchr(yytext,'r');
                        g_assert(p); /* we MUST have found it */
                        sscanf(p,"requires %d.%d.%d",&maj,&min,&pl);
+                       effective_maj = maj;
+                       if (min >= 90)
+                               effective_maj = maj + 1;
+
                        if(rmaj < maj ||
                           (rmaj == maj && rmin < min) ||
                           (rmaj == maj && rmin == min && rpl < pl)) {
-                               char *s;
-                               s = g_strdup_printf(
-                                   "GOB version %d.%d.%d required "
-                                   "(this is %s)\n"
-                                   "To upgrade your gob, see: "
-                                   "http://www.5z.com/jirka/gob.html",
-                                   maj,min,pl,VERSION);
-                               print_error(FALSE, s, line_no);
-                               g_free(s);
+                               error_printf(GOB_ERROR, line_no,
+                                            "GOB version at least %d.%d.%d required "
+                                            "(this is %s)\n"
+                                            "To upgrade your gob, see: "
+                                            "http://www.5z.com/jirka/gob.html",
+                                            maj, min, pl, VERSION);
+                       }
+
+                       if(effective_rmaj != effective_maj) {
+                               error_printf(GOB_ERROR, line_no,
+                                            "GOB major version %d required "
+                                            "(this is %s)\n"
+                                            "To upgrade your gob, see: "
+                                            "http://www.5z.com/jirka/gob.html",
+                                            maj, VERSION);
                        }
                }
 
 <CLASS_CODE,CLASS_CODE_I>class|this    {
                        if(for_cpp) {
-                               char *s;
-                               s = g_strdup_printf("'%s' keyword should not "
-                                                   "be used when generating "
-                                                   "C++ code", yytext);
-                               print_error(TRUE, s, line_no);
-                               g_free(s);
+                               error_printf(GOB_WARN, line_no,
+                                            "'%s' keyword should not "
+                                            "be used when generating "
+                                            "C++ code", yytext);
                        }
                        REJECT;
                }
@@ -446,7 +500,7 @@ class               {
                                return '}';
                        }
 
-<CLASS_CODE,CLASS_CODE_I,INITIAL>[\t ] ;  /*ignore*/
+<CLASS_CODE,CLASS_CODE_I,INITIAL>[\f\t ]       ;  /*ignore*/
 
 <*>.           {
                        yylval.line = line_no;