diff --git a/parser/parser.h b/parser/parser.h index 3677506ad..346620abf 100644 --- a/parser/parser.h +++ b/parser/parser.h @@ -271,6 +271,7 @@ extern struct var_string *split_out_var(char *string); extern void free_var_string(struct var_string *var); /* parser_misc.c */ +extern char *processid(char *string, int len); extern char *processquoted(char *string, int len); extern char *processunquoted(char *string, int len); extern int get_keyword_token(const char *keyword); diff --git a/parser/parser_lex.l b/parser/parser_lex.l index 2f2b7fc79..5cb24fbe4 100644 --- a/parser/parser_lex.l +++ b/parser/parser_lex.l @@ -247,7 +247,7 @@ LT_EQUAL <= } { - {ID}+ { + ({ID}+|{QUOTED_ID}) { /* Ugh, this is a gross hack. I used to use * {ID}+ to match all TOK_IDs, but that would * also match TOK_MODE + TOK_END_OF_RULE @@ -256,25 +256,11 @@ LT_EQUAL <= * match any random string, I go into a * separate state. */ DUMP_PREPROCESS; - yylval.id = processunquoted(yytext, yyleng); + yylval.id = processid(yytext, yyleng); PDEBUG("Found sub name: \"%s\"\n", yylval.id); yy_pop_state(); return TOK_ID; } - {QUOTED_ID} { - /* Ugh, this is a gross hack. I used to use - * {ID}+ to match all TOK_IDs, but that would - * also match TOK_MODE + TOK_END_OF_RULE - * without any spaces in between (because it's - * a longer match). So now, when I want to - * match any random string, I go into a - * separate state. */ - DUMP_PREPROCESS; - yylval.id = processquoted(yytext, yyleng); - PDEBUG("Found sub name: \"%s\"\n", yylval.id); - yy_pop_state(); - return TOK_ID; - } [^\n] { DUMP_PREPROCESS; @@ -284,7 +270,7 @@ LT_EQUAL <= } { - {ID}+ { + ({ID}+|{QUOTED_ID}) { /* Ugh, this is a gross hack. I used to use * {ID}+ to match all TOK_IDs, but that would * also match TOK_MODE + TOK_END_OF_RULE @@ -293,21 +279,7 @@ LT_EQUAL <= * match any random string, I go into a * separate state. */ DUMP_PREPROCESS; - yylval.id = processunquoted(yytext, yyleng); - PDEBUG("Found sub name: \"%s\"\n", yylval.id); - yy_pop_state(); - return TOK_ID; - } - {QUOTED_ID} { - /* Ugh, this is a gross hack. I used to use - * {ID}+ to match all TOK_IDs, but that would - * also match TOK_MODE + TOK_END_OF_RULE - * without any spaces in between (because it's - * a longer match). So now, when I want to - * match any random string, I go into a - * separate state. */ - DUMP_PREPROCESS; - yylval.id = processquoted(yytext, yyleng); + yylval.id = processid(yytext, yyleng); PDEBUG("Found sub name: \"%s\"\n", yylval.id); yy_pop_state(); return TOK_ID; @@ -364,16 +336,9 @@ LT_EQUAL <= { {WS}+ { DUMP_PREPROCESS; /* Eat whitespace */ } - {ID}+ { + ({ID}+|{QUOTED_ID}) { DUMP_PREPROCESS; - yylval.var_val = processunquoted(yytext, yyleng); - PDEBUG("Found assignment value: \"%s\"\n", yylval.var_val); - return TOK_VALUE; - } - - {QUOTED_ID} { - DUMP_PREPROCESS; - yylval.var_val = processquoted(yytext, yyleng); + yylval.var_val = processid(yytext, yyleng); PDEBUG("Found assignment value: \"%s\"\n", yylval.var_val); return TOK_VALUE; } @@ -431,7 +396,7 @@ LT_EQUAL <= return TOK_ARROW; } - {ID}+ { + ({ID}+|{QUOTED_ID}) { /* Ugh, this is a gross hack. I used to use * {ID}+ to match all TOK_IDs, but that would * also match TOK_MODE + TOK_END_OF_RULE @@ -440,25 +405,11 @@ LT_EQUAL <= * match any random string, I go into a * separate state. */ DUMP_PREPROCESS; - yylval.id = processunquoted(yytext, yyleng); + yylval.id = processid(yytext, yyleng); PDEBUG("Found change profile name: \"%s\"\n", yylval.id); yy_pop_state(); return TOK_ID; } - {QUOTED_ID} { - /* Ugh, this is a gross hack. I used to use - * {ID}+ to match all TOK_IDs, but that would - * also match TOK_MODE + TOK_END_OF_RULE - * without any spaces in between (because it's - * a longer match). So now, when I want to - * match any random string, I go into a - * separate state. */ - DUMP_PREPROCESS; - yylval.id = processquoted(yytext, yyleng); - PDEBUG("Found change profile quoted name: \"%s\"\n", yylval.id); - yy_pop_state(); - return TOK_ID; - } {WS}+ { DUMP_PREPROCESS; /* Ignoring whitespace */ } [^\n] { @@ -568,16 +519,9 @@ LT_EQUAL <= return TOK_CLOSE; } -{PATHNAME} { +({PATHNAME}|{QPATHNAME}) { DUMP_PREPROCESS; - yylval.id = processunquoted(yytext, yyleng); - PDEBUG("Found id: \"%s\"\n", yylval.id); - return TOK_ID; - } - -{QPATHNAME} { - DUMP_PREPROCESS; - yylval.id = processquoted(yytext, yyleng); + yylval.id = processid(yytext, yyleng); PDEBUG("Found id: \"%s\"\n", yylval.id); return TOK_ID; } diff --git a/parser/parser_misc.c b/parser/parser_misc.c index 5aafaecee..e438d4ebd 100644 --- a/parser/parser_misc.c +++ b/parser/parser_misc.c @@ -17,6 +17,7 @@ /* assistance routines */ +#include #include #include #include @@ -397,6 +398,16 @@ char *processunquoted(char *string, int len) return tmp; } +char *processid(char *string, int len) +{ + /* lexer should never call this fn if len <= 0 */ + assert(len > 0); + + if (*string == '"') + return processquoted(string, len); + return processunquoted(string, len); +} + /* rewrite a quoted string substituting escaped characters for the * real thing. Strip the quotes around the string */