X-Git-Url: http://git.draconx.ca/gitweb/gob-dx.git/blobdiff_plain/b9f22ab5a7f4d4bfe0932debf8864a21b5c852cd..2310330e7d4d724bf6641339836be8523f95c916:/src/lexer.l diff --git a/src/lexer.l b/src/lexer.l index ebfc187..aabc7ad 100644 --- a/src/lexer.l +++ b/src/lexer.l @@ -24,6 +24,9 @@ #include #include "parse.h" +#include "main.h" + +extern gboolean for_cpp; static int parenth_depth = 0; static int before_comment = INITIAL; @@ -31,6 +34,7 @@ static int class_after_c = FALSE; static int header_c = FALSE; static GString *cbuf = NULL; +int ccode_line = 1; int line_no = 1; @@ -66,16 +70,32 @@ add_to_cbuf(char *s) <*>\n { line_no++; REJECT; } +<*>MOTHERFUCKER { fprintf(stderr,"You are a bad bad person!\n"); REJECT; } + \/\/.*$ { ; /*comment, ignore*/ } -\/\/.*$ { ; /*comment, ignore*/ } +\/\/.*$ { 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); @@ -83,6 +103,7 @@ add_to_cbuf(char *s) class_after_c = FALSE; header_c = TRUE; clear_cbuf(); + ccode_line = line_no; } ^\%\{ { BEGIN(C_CODE); @@ -90,6 +111,7 @@ add_to_cbuf(char *s) class_after_c = FALSE; header_c = FALSE; clear_cbuf(); + ccode_line = line_no; } ^\%\} { BEGIN(INITIAL); @@ -105,22 +127,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++; @@ -147,6 +168,18 @@ class { 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;} @@ -161,18 +194,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); @@ -195,6 +226,8 @@ class { BEGIN(C_CODE); parenth_depth=1; class_after_c = TRUE; + ccode_line = line_no; + yylval.line = line_no; return '{'; } \} { @@ -202,9 +235,11 @@ class { return '}'; } -[\n\t ] ; /*ignore*/ +[\t ] ; /*ignore*/ <*>. { yylval.line = line_no; return yytext[0]; } + +<*>[\n\r] ; /*ignore*/