X-Git-Url: http://git.draconx.ca/gitweb/gob-dx.git/blobdiff_plain/c190a2ae41238682c1430b8482683b6a7c15c66b..40647d7b7b7fbeae828e0a032a3c3a5f204cdfa8:/src/lexer.l diff --git a/src/lexer.l b/src/lexer.l index 92454f2..320e25b 100644 --- a/src/lexer.l +++ b/src/lexer.l @@ -20,9 +20,14 @@ */ %{ +#include "config.h" #include +#include -#include "y.tab.h" +#include "parse.h" +#include "main.h" + +extern gboolean for_cpp; static int parenth_depth = 0; static int before_comment = INITIAL; @@ -30,6 +35,11 @@ static int class_after_c = FALSE; 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; @@ -65,16 +75,49 @@ add_to_cbuf(char *s) <*>\n { line_no++; REJECT; } +<*>MOTHERFUCKER { fprintf(stderr,"You are a bad bad person!\n"); REJECT; } + \/\/.*$ { ; /*comment, ignore*/ } -\/\/.*$ { ; /*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*/ } \/\* {BEGIN(COMMENT); before_comment = INITIAL; } -\/\* {BEGIN(COMMENT); before_comment = C_CODE; } +\/\* { + add_to_cbuf(yytext); + BEGIN(COMMENT); + before_comment = C_CODE; +} \/\* {BEGIN(COMMENT); before_comment = CLASS_CODE; } \/\* {BEGIN(COMMENT); before_comment = CLASS_CODE_I; } -\*\/ {BEGIN(before_comment);} -. { ; /* comment, ignore */ } +\*\/ { + if(before_comment == C_CODE) add_to_cbuf(yytext); + BEGIN(before_comment); + } +. { + /* comment, ignore */ + if(before_comment == C_CODE) add_to_cbuf(yytext); + } +\n { + /* comment, ignore */ + if(before_comment == C_CODE) add_to_cbuf(yytext); + } ^\%h\{ { BEGIN(C_CODE); @@ -82,6 +125,7 @@ add_to_cbuf(char *s) class_after_c = FALSE; header_c = TRUE; clear_cbuf(); + ccode_line = line_no; } ^\%\{ { BEGIN(C_CODE); @@ -89,11 +133,16 @@ add_to_cbuf(char *s) class_after_c = FALSE; 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 @@ -104,22 +153,21 @@ add_to_cbuf(char *s) \'\\\{\' { add_to_cbuf(yytext); } \'\}\' { add_to_cbuf(yytext); } \'\\\}\' { add_to_cbuf(yytext); } +\'\"\' { add_to_cbuf(yytext); } +\'\\\"\' { add_to_cbuf(yytext); } \\. { add_to_cbuf(yytext); } \" { BEGIN(C_CODE_STRING); add_to_cbuf(yytext); } -\\. { - add_to_cbuf(yytext); - } +\\. { add_to_cbuf(yytext); } \" { BEGIN(C_CODE); add_to_cbuf(yytext); } -. { - add_to_cbuf(yytext); - } +. { add_to_cbuf(yytext); } +\n { add_to_cbuf(yytext); } \{ { parenth_depth++; @@ -142,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;} @@ -160,18 +221,16 @@ class { float {return FLOAT;} double {return DOUBLE;} char {return CHAR;} +const {return CONST;} + +\.\.\. {return THREEDOTS;} public {yylval.line = line_no; return PUBLIC;} private {yylval.line = line_no; return PRIVATE;} argument {yylval.line = line_no; return ARGUMENT;} virtual {yylval.line = line_no; return VIRTUAL;} signal {yylval.line = line_no; return SIGNAL;} -last {return LAST;} -first {return FIRST;} override {yylval.line = line_no; return OVERRIDE;} -check {return CHECK;} -null {return CNULL;} -type {return TYPE;} onerror {return ONERROR;} 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); @@ -194,6 +253,8 @@ class { BEGIN(C_CODE); parenth_depth=1; class_after_c = TRUE; + ccode_line = line_no; + yylval.line = line_no; return '{'; } \} { @@ -201,9 +262,11 @@ class { return '}'; } -[\n\t ] ; /*ignore*/ +[\t ] ; /*ignore*/ <*>. { yylval.line = line_no; return yytext[0]; } + +<*>[\n\r] ; /*ignore*/