From 60244428d2ef1af082c99acce6e51da9ef247eec Mon Sep 17 00:00:00 2001 From: Matijn Woudt Date: Wed, 3 Jun 2009 01:04:12 +0200 Subject: wrc: Add support for nameID with quotes --- tools/wrc/parser.l | 39 ++++++++++++++++++++++++++++++++------- 1 files changed, 32 insertions(+), 7 deletions(-) diff --git a/tools/wrc/parser.l b/tools/wrc/parser.l index bddc309..5b92ce3 100644 --- a/tools/wrc/parser.l +++ b/tools/wrc/parser.l @@ -125,7 +125,7 @@ static void addcchar(char c); static void addwchar(WCHAR s); static string_t *get_buffered_cstring(void); static string_t *get_buffered_wstring(void); -static string_t *make_string(char *s); +static string_t *make_string(char *s, int withQuotes); static char *cbuffer; /* Buffers for string collection */ static int cbufidx; @@ -411,7 +411,7 @@ static unsigned long xstrtoul(const char *nptr, char **endptr, int base) { if(wanted_id && !tok->alwayskw) { - parser_lval.str = make_string(yytext); + parser_lval.str = make_string(yytext, 0); return tIDENT; } else @@ -419,11 +419,30 @@ static unsigned long xstrtoul(const char *nptr, char **endptr, int base) } else { - parser_lval.str = make_string(yytext); + parser_lval.str = make_string(yytext, 0); return tIDENT; } } -[A-Za-z_0-9./\\]+ parser_lval.str = make_string(yytext); return tFILENAME; +["][A-Za-z_0-9.]+["] { + struct keyword *tok = iskeyword(yytext); + + if(tok) + { + if(wanted_id && !tok->alwayskw) + { + parser_lval.str = make_string(yytext, 1); + return tIDENT; + } + else + return tok->token; + } + else + { + parser_lval.str = make_string(yytext, 1); + return tIDENT; + } + } +[A-Za-z_0-9./\\]+ parser_lval.str = make_string(yytext, 0); return tFILENAME; /* * Wide string scanning @@ -650,12 +669,18 @@ static string_t *get_buffered_wstring(void) return str; } -static string_t *make_string(char *s) +static string_t *make_string(char *s, int withQuotes) { string_t *str = new_string(); str->size = strlen(s); str->type = str_char; - str->str.cstr = xmalloc(str->size+1); - memcpy(str->str.cstr, s, str->size+1); + if(withQuotes) { + str->str.cstr = xmalloc(str->size-1); + *(s + str->size - 1) = 0; + memcpy(str->str.cstr, s+1, str->size-1); + } else { + str->str.cstr = xmalloc(str->size+1); + memcpy(str->str.cstr, s, str->size+1); + } return str; } -- 1.6.0.4