X-Git-Url: https://git.draconx.ca/gitweb/gob-dx.git/blobdiff_plain/714b58ab4606ed4d40cec3702cb378938f8c883f..7231d76fbf4ae0b501af648e1216b88714aa7353:/src/lexer.l diff --git a/src/lexer.l b/src/lexer.l index f45fcc5..e102286 100644 --- a/src/lexer.l +++ b/src/lexer.l @@ -33,6 +33,8 @@ static int parenth_depth = 0; static int before_comment = INITIAL; static gboolean class_after_c = FALSE; static int code_type = CCODE; +static int before_string; +static int property_paren_depth = 0; /* GTK+ doc stuff */ static char *gtk_doc_func = NULL; /* current gtk-doc func */ @@ -90,9 +92,11 @@ int yylex(void); %x COMMENT %x C_CODE -%x C_CODE_STRING +%x CODE_STRING %x CLASS_CODE %x CLASS_CODE_I +%x PROPERTY_CODE +%x PROPERTY_CODE_I %x GTK_DOC_BEFORE_NAME %x GTK_DOC %x GTK_DOC_LINE @@ -101,6 +105,14 @@ int yylex(void); %% +%{ +/* Avoid warning from flex, cuz flex sucks */ +#ifdef FLEX_SCANNER +yy_current_state = 0; +#endif +%} + + <*>\n { line_no++; REJECT; } ^(I(S.RI).E\(([1-9][0-9]+|[2-9]))/(\)) { @@ -296,17 +308,31 @@ REJECT; \'\\\"\' { add_to_cbuf(yytext); } \\. { add_to_cbuf(yytext); } + + \" { - BEGIN(C_CODE_STRING); + BEGIN(CODE_STRING); + before_string = C_CODE; + add_to_cbuf(yytext); + } +\" { + BEGIN(CODE_STRING); + before_string = PROPERTY_CODE_I; add_to_cbuf(yytext); } -\\. { add_to_cbuf(yytext); } -\" { - BEGIN(C_CODE); - add_to_cbuf(yytext); +\\. { add_to_cbuf(yytext); } +\" { + BEGIN(before_string); + add_to_cbuf(yytext); + if (before_string == PROPERTY_CODE_I) { + yylval.id = cbuf->str; + g_string_free (cbuf, FALSE); + cbuf = NULL; + return STRING; } -. { add_to_cbuf(yytext); } -\n { add_to_cbuf(yytext); } + } +. { add_to_cbuf(yytext); } +\n { add_to_cbuf(yytext); } \{ { parenth_depth++; @@ -342,24 +368,44 @@ 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; + int maj = 0, min = 0, pl = 0; + int rmaj = 0, rmin = 0, rpl = 0; + int effective_maj = 0; + int effective_rmaj = 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); + sscanf (VERSION, "%d.%d.%d", &rmaj, &rmin, &rpl); + effective_rmaj = rmaj; + if (rmin >= 90) + effective_rmaj = rmaj + 1; + + p = strchr (yytext,'r'); + g_assert (p); /* we MUST have found it */ + sscanf (p, "requires %d.%d.%d", &maj, &min, &pl); + effective_maj = maj; + if (min >= 90) + effective_maj = maj + 1; + if(rmaj < maj || (rmaj == maj && rmin < min) || (rmaj == maj && rmin == min && rpl < pl)) { + error_printf (GOB_ERROR, line_no, + "GOB version at least %d.%d.%d required " + "(this is %s)\n" + "To upgrade your gob, see: " + "http://www.5z.com/jirka/gob.html", + maj, min, pl, VERSION); + } + + if(effective_rmaj != effective_maj) { error_printf(GOB_ERROR, line_no, - "GOB version %d.%d.%d required " + "GOB major version %d required " "(this is %s)\n" "To upgrade your gob, see: " "http://www.5z.com/jirka/gob.html", - maj, min, pl, VERSION); + maj, VERSION); } + } class|this { @@ -374,19 +420,19 @@ class { from {return FROM;} -void {return VOID;} -struct {return STRUCT;} -union {return UNION;} -enum {return ENUM;} -signed {return SIGNED;} -unsigned {return UNSIGNED;} -long {return LONG;} -short {return SHORT;} -int {return INT;} -float {return FLOAT;} -double {return DOUBLE;} -char {return CHAR;} -const {return CONST;} +void {return VOID;} +struct {return STRUCT;} +union {return UNION;} +enum {return ENUM;} +signed {return SIGNED;} +unsigned {return UNSIGNED;} +long {return LONG;} +short {return SHORT;} +int {return INT;} +float {return FLOAT;} +double {return DOUBLE;} +char {return CHAR;} +const {return CONST;} \.\.\. {return THREEDOTS;} @@ -398,24 +444,65 @@ class { virtual {yylval.line = line_no; return VIRTUAL;} signal {yylval.line = line_no; return SIGNAL;} override {yylval.line = line_no; return OVERRIDE;} -0|[1-9][0-9]*|0x[0-9a-fA-F]+|0[0-7]+|[0-9]*\.[0-9]+|\.[0-9][0-9]* { +property { + yylval.line = line_no; + BEGIN(PROPERTY_CODE); + return PROPERTY; + } +nick { yylval.line = line_no; return NICK; } +blurb { yylval.line = line_no; return BLURB; } +maximum { yylval.line = line_no; return MAXIMUM; } +minimum { yylval.line = line_no; return MINIMUM; } +default_value { yylval.line = line_no; return DEFAULT_VALUE; } +flags { yylval.line = line_no; return FLAGS; } +type { yylval.line = line_no; return TYPE; } +flags_type { yylval.line = line_no; return FLAGS_TYPE; } +enum_type { yylval.line = line_no; return ENUM_TYPE; } +param_type { yylval.line = line_no; return PARAM_TYPE; } +boxed_type { yylval.line = line_no; return BOXED_TYPE; } +object_type { yylval.line = line_no; return OBJECT_TYPE; } +[(] { + yylval.line = line_no; + property_paren_depth = 1; + BEGIN(PROPERTY_CODE_I); + return '('; + } +[(] { + yylval.line = line_no; + property_paren_depth++; + return '('; + } +[)] { + yylval.line = line_no; + property_paren_depth--; + if (property_paren_depth == 0) { + BEGIN(CLASS_CODE_I); + } + return ')'; + } + +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); 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 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-z0-9_]*)* { /* this is for a classname with an empty namespace */ yylval.id = g_strdup(yytext); return TYPETOKEN; } -[A-Za-z_][A-Za-z0-9_]* { +[A-Za-z_][A-Za-z0-9_]* { yylval.id = g_strdup(yytext); return TOKEN; } +\'\\.\'|\'.\' { + yylval.id = g_strdup(yytext); + return SINGLE_CHAR; + } (\[[0-9]*\]|\[[A-Za-z_][A-Za-z0-9_]*\])+ { yylval.id = g_strdup(yytext); @@ -440,7 +527,7 @@ class { return '}'; } -[\t ] ; /*ignore*/ +[\t ] ; /*ignore*/ <*>. { yylval.line = line_no;