X-Git-Url: https://git.draconx.ca/gitweb/gob-dx.git/blobdiff_plain/489e97ede850a8de01ca3bd653dce9c25dcd54a1..86d4727e727a55648196205cff450c96569ec4a6:/src/lexer.l diff --git a/src/lexer.l b/src/lexer.l index aa9b6d2..d33965d 100644 --- a/src/lexer.l +++ b/src/lexer.l @@ -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 * @@ -18,12 +22,14 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, * USA. */ -%{ +#include +} -#include "config.h" -#include +%{ +#include #include #include +#include #include "treefuncs.h" #include "parse.h" @@ -31,7 +37,13 @@ #include "util.h" static int parenth_depth = 0; -static int before_comment = INITIAL; +static int before_comment +/* New flex is on drugs */ +#if defined(FLEX_SCANNER) && ! defined(INITIAL) + = 0; +#else + = INITIAL; +#endif static gboolean class_after_c = FALSE; static int code_type = CCODE; static int before_string; @@ -86,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 %} @@ -97,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 @@ -179,7 +193,7 @@ REJECT; g_free(str); } -^#[ \t]*include[ \t][<"][^\n">]*[>"] { +^#[ \t]*include[ \t][<"][^\n\r">]*[>"] { if(look_for_includes==1) { char *p; char *file; @@ -189,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; } @@ -230,7 +246,7 @@ REJECT; BEGIN(CLASS_CODE_I); add_gtk_doc_func(); } -^[ \t]*\*\ { +^[ \t]*\*[ \t] { fflush(stdout); add_to_cbuf(" * "); BEGIN(GTK_DOC_LINE); @@ -334,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; + } ^\%\} { BEGIN(INITIAL); yylval.cbuf = cbuf; @@ -466,6 +500,28 @@ flags { return FLAGS; } } from {return FROM;} +\" { + BEGIN(CLASS_STRING); + before_string = CLASS_CODE; + add_to_cbuf(yytext); + } +\\. { add_to_cbuf(yytext); } +\" { + BEGIN(before_string); + add_to_cbuf(yytext); + yylval.id = cbuf->str; + g_string_free (cbuf, FALSE); + cbuf = NULL; + return STRING; + } +. { add_to_cbuf(yytext); } +\n { add_to_cbuf(yytext); } + +\" { + BEGIN(CLASS_STRING); + before_string = CLASS_CODE_I; + add_to_cbuf(yytext); + } void {return VOID;} struct {return STRUCT;} @@ -497,6 +553,7 @@ flags { return FLAGS; } return PROPERTY; } nick { yylval.line = line_no; return NICK; } +name { yylval.line = line_no; return NAME; } blurb { yylval.line = line_no; return BLURB; } maximum { yylval.line = line_no; return MAXIMUM; } minimum { yylval.line = line_no; return MINIMUM; } @@ -532,12 +589,21 @@ flags { return FLAGS; } yylval.id = g_strdup(yytext); return NUMBER; } -[A-Za-z_][A-Za-z0-9_]*(:[A-Za-z0-9_]*)+ { +[A-Za-z_][A-Za-z0-9_]*(::[A-Za-z0-9_]*)+ { + /* This is cpp kind of token thingie */ + if (for_cpp) { + yylval.id = g_strdup(yytext); + return TOKEN; + } else { + REJECT; + } + } +[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; } -:[A-Za-z_][A-Za-z0-9_]*(:[A-Za-z0-9_]*)* { +:[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; @@ -555,12 +621,16 @@ flags { return FLAGS; } yylval.id = g_strdup(yytext); return ARRAY_DIM; } - +:[0-9]+ { + /* cheat for bitfield */ + yylval.id = g_strdup(yytext); + return ARRAY_DIM; + } \{ { BEGIN(CLASS_CODE_I); return '{'; } -\{ { +\{ { BEGIN(C_CODE); parenth_depth=1; class_after_c = TRUE; @@ -576,22 +646,21 @@ flags { return FLAGS; } [\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; + } %% - -/* Ugly warning avoiding */ -#ifdef FLEX_SCANNER -static void warning_avoider(void) G_GNUC_UNUSED; -static void warning_avoider(void) { - yy_flex_realloc(NULL, 0); - yyunput(0, NULL); - warning_avoider(); -} -#endif -