X-Git-Url: http://git.draconx.ca/gitweb/gob-dx.git/blobdiff_plain/8cb6370effd9f2dacc6dc9b662a43ea19ee637ac..f31590988781d77ff5249987801d03a986368ca2:/src/lexer.l diff --git a/src/lexer.l b/src/lexer.l index 0037b85..35e42cc 100644 --- a/src/lexer.l +++ b/src/lexer.l @@ -22,8 +22,12 @@ #include "config.h" #include +#include #include "parse.h" +#include "main.h" + +extern gboolean for_cpp; static int parenth_depth = 0; static int before_comment = INITIAL; @@ -33,6 +37,10 @@ static int header_c = FALSE; static GString *cbuf = NULL; int ccode_line = 1; +GList *include_files = NULL; +/* 0 no, 1 means yes, 2+ means don't even start looking anymore */ +static int look_for_includes = 0; + int line_no = 1; static void @@ -70,6 +78,23 @@ add_to_cbuf(char *s) <*>MOTHERFUCKER { fprintf(stderr,"You are a bad bad person!\n"); REJECT; } \/\/.*$ { ; /*comment, ignore*/ } +^#[ \t]*include[ \t][<"][^\n">]*[>"] { + if(look_for_includes==1) { + char *p; + char *file; + char *str = g_strdup(yytext); + file = strchr(str,'"'); + if(!file) file = strchr(str,'<'); + file++; + p = strchr(file,'"'); + if(!p) p = strchr(file,'>'); + *p = '\0'; + include_files = g_list_prepend(include_files,g_strdup(file)); + g_free(str); + } + REJECT; +} + \/\/.*$ { add_to_cbuf(yytext); /*comment, ignore*/ } \/\/.*$ { ; /*comment, ignore*/ } \/\/.*$ { ; /*comment, ignore*/ } @@ -109,11 +134,15 @@ add_to_cbuf(char *s) header_c = FALSE; clear_cbuf(); ccode_line = line_no; + if(look_for_includes==0) + look_for_includes=1; } ^\%\} { BEGIN(INITIAL); yylval.cbuf = cbuf; cbuf = NULL; + if(look_for_includes==1) + look_for_includes=0; if(header_c) return HCODE; else @@ -161,10 +190,23 @@ add_to_cbuf(char *s) \n { add_to_cbuf(yytext); } class { + look_for_includes = 2; BEGIN(CLASS_CODE); return CLASS; } +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); + } + REJECT; + } + from {return FROM;} void {return VOID;} @@ -203,6 +245,11 @@ class { return TOKEN; } +(\[[0-9]*\])+ { + yylval.id = g_strdup(yytext); + return ARRAY_DIM; + } + \{ { BEGIN(CLASS_CODE_I); return '{';