X-Git-Url: http://git.draconx.ca/gitweb/gob-dx.git/blobdiff_plain/f31590988781d77ff5249987801d03a986368ca2..b17287deb56775a49030d738d8c8c0e9cd15f9fe:/src/lexer.l diff --git a/src/lexer.l b/src/lexer.l index 35e42cc..ddbd951 100644 --- a/src/lexer.l +++ b/src/lexer.l @@ -26,13 +26,16 @@ #include "parse.h" #include "main.h" - -extern gboolean for_cpp; +#include "util.h" static int parenth_depth = 0; static int before_comment = INITIAL; -static int class_after_c = FALSE; -static int header_c = FALSE; +static gboolean class_after_c = FALSE; +static int code_type = CCODE; + +/* GTK+ doc stuff */ +static char *gtk_doc_func = NULL; /* current gtk-doc func */ +GHashTable *gtk_doc_hash = NULL; static GString *cbuf = NULL; int ccode_line = 1; @@ -63,6 +66,21 @@ add_to_cbuf(char *s) } } +static void +add_gtk_doc_func(void) +{ + if(!gtk_doc_func) + return; + + if(!gtk_doc_hash) + gtk_doc_hash = g_hash_table_new(g_str_hash, g_str_equal); + g_hash_table_insert(gtk_doc_hash, gtk_doc_func, g_strdup(cbuf->str)); + clear_cbuf(); + + gtk_doc_func = NULL; +} + + %} %x COMMENT @@ -70,6 +88,9 @@ add_to_cbuf(char *s) %x C_CODE_STRING %x CLASS_CODE %x CLASS_CODE_I +%x GTK_DOC_BEFORE_NAME +%x GTK_DOC +%x GTK_DOC_LINE %% @@ -95,6 +116,67 @@ add_to_cbuf(char *s) REJECT; } +\/\*\*[ \t]*$ { + /* eat out gtk doc stuff */ + BEGIN(GTK_DOC_BEFORE_NAME); + clear_cbuf(); + } +^[ \t]*\*[ \t]*$ { + /* empty doc lines */ + ; + } +^[ \t]*\*\ [_a-zA-Z][_a-zA-Z0-9]*:?[ \t]*$ { + char *p; + BEGIN(GTK_DOC); + p = strchr(yytext, '*'); + g_free(gtk_doc_func); + gtk_doc_func = g_strdup(p+2); + p = strchr(gtk_doc_func, ':'); + if(p) *p='\0'; + g_strstrip(gtk_doc_func); + } +\*\/ { + BEGIN(CLASS_CODE_I); + } +. { + BEGIN(COMMENT); + before_comment = CLASS_CODE_I; + } +^[ \t]*\*[ \t]*$ { + /* empty doc lines */ + add_to_cbuf(" *\n"); + } +^[ \t]*\*?\*\/ { + BEGIN(CLASS_CODE_I); + add_gtk_doc_func(); + } +^[ \t]*\*\ { + fflush(stdout); + add_to_cbuf(" * "); + BEGIN(GTK_DOC_LINE); + } +\*\/ { + BEGIN(CLASS_CODE_I); + } +. { + BEGIN(COMMENT); + before_comment = CLASS_CODE_I; + } +\*\/ { + BEGIN(CLASS_CODE_I); + add_to_cbuf("\n"); + add_gtk_doc_func(); + } +.$ { + BEGIN(GTK_DOC); + add_to_cbuf(yytext); + add_to_cbuf("\n"); + } +. { + fflush(stdout); + add_to_cbuf(yytext); + } + \/\/.*$ { add_to_cbuf(yytext); /*comment, ignore*/ } \/\/.*$ { ; /*comment, ignore*/ } \/\/.*$ { ; /*comment, ignore*/ } @@ -119,11 +201,44 @@ add_to_cbuf(char *s) if(before_comment == C_CODE) add_to_cbuf(yytext); } -^\%h\{ { +^\%(a|all)\{ { BEGIN(C_CODE); parenth_depth = 1; class_after_c = FALSE; - header_c = TRUE; + code_type = ACODE; + clear_cbuf(); + ccode_line = line_no; + } +^\%(at|alltop)\{ { + BEGIN(C_CODE); + parenth_depth = 1; + class_after_c = FALSE; + code_type = ATCODE; + clear_cbuf(); + ccode_line = line_no; + } + +^\%(ht|headertop)\{ { + BEGIN(C_CODE); + parenth_depth = 1; + class_after_c = FALSE; + code_type = HTCODE; + clear_cbuf(); + ccode_line = line_no; + } +^\%(ph|privateheader)\{ { + BEGIN(C_CODE); + parenth_depth = 1; + class_after_c = FALSE; + code_type = PHCODE; + clear_cbuf(); + ccode_line = line_no; + } +^\%(h|header)\{ { + BEGIN(C_CODE); + parenth_depth = 1; + class_after_c = FALSE; + code_type = HCODE; clear_cbuf(); ccode_line = line_no; } @@ -131,7 +246,7 @@ add_to_cbuf(char *s) BEGIN(C_CODE); parenth_depth = 1; class_after_c = FALSE; - header_c = FALSE; + code_type = CCODE; clear_cbuf(); ccode_line = line_no; if(look_for_includes==0) @@ -143,10 +258,7 @@ add_to_cbuf(char *s) cbuf = NULL; if(look_for_includes==1) look_for_includes=0; - if(header_c) - return HCODE; - else - return CCODE; + return code_type; } \'\{\' { add_to_cbuf(yytext); } @@ -190,18 +302,50 @@ add_to_cbuf(char *s) \n { add_to_cbuf(yytext); } class { + static int found_classes = 0; look_for_includes = 2; BEGIN(CLASS_CODE); + + if(++found_classes > 1) { + print_error(FALSE, + "Only one class per file allowed", + line_no); + } + return 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; + char *p; + + sscanf(VERSION,"%d.%d.%d",&rmaj,&rmin,&rpl); + p = strchr(yytext,'r'); + g_assert(p); /* we MUST have found it */ + sscanf(p,"requires %d.%d.%d",&maj,&min,&pl); + 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); + } + } + 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); + print_error(TRUE, s, line_no); g_free(s); } REJECT; @@ -227,6 +371,7 @@ class { public {yylval.line = line_no; return PUBLIC;} private {yylval.line = line_no; return PRIVATE;} +protected {yylval.line = line_no; return PROTECTED;} argument {yylval.line = line_no; return ARGUMENT;} virtual {yylval.line = line_no; return VIRTUAL;} signal {yylval.line = line_no; return SIGNAL;} @@ -258,8 +403,9 @@ class { BEGIN(C_CODE); parenth_depth=1; class_after_c = TRUE; - ccode_line = line_no; yylval.line = line_no; + clear_cbuf(); + ccode_line = line_no; return '{'; } \} {