Code

frontend/scanner: Simplified handling of reserved words.
authorSebastian Harl <sh@tokkee.org>
Wed, 30 Jul 2014 09:44:06 +0000 (11:44 +0200)
committerSebastian Harl <sh@tokkee.org>
Wed, 30 Jul 2014 09:44:06 +0000 (11:44 +0200)
src/frontend/scanner.l

index f45fbe76bdbb86370e27cf4d4583275414831d34..f70f60f84dab33618a7ae84a67771ec33e0a022f 100644 (file)
 
 #define YY_EXTRA_TYPE sdb_fe_yyextra_t *
 
+static struct {
+       const char *name;
+       int id;
+} reserved_words[] = {
+       { "AND",      AND },
+       { "FETCH",    FETCH },
+       { "IS",       IS },
+       { "LIST",     LIST },
+       { "LOOKUP",   LOOKUP },
+       { "MATCHING", MATCHING },
+       { "NOT",      NOT },
+       { "NULL",     NULL_T },
+       { "OR",       OR },
+};
+
 void
 sdb_fe_yyerror(YYLTYPE *lval, sdb_fe_yyscan_t scanner, const char *msg);
 
@@ -109,25 +124,10 @@ float             ({float1}|{float2}|{float3}|{float4}|{float5})
        }
 
 {identifier} {
-               /* XXX: simplify handling of reserved words */
-               if (! strcasecmp(yytext, "AND"))
-                       return AND;
-               else if (! strcasecmp(yytext, "FETCH"))
-                       return FETCH;
-               else if (! strcasecmp(yytext, "IS"))
-                       return IS;
-               else if (! strcasecmp(yytext, "LIST"))
-                       return LIST;
-               else if (! strcasecmp(yytext, "LOOKUP"))
-                       return LOOKUP;
-               else if (! strcasecmp(yytext, "MATCHING"))
-                       return MATCHING;
-               else if (! strcasecmp(yytext, "NOT"))
-                       return NOT;
-               else if (! strcasecmp(yytext, "NULL"))
-                       return NULL_T;
-               else if (! strcasecmp(yytext, "OR"))
-                       return OR;
+               size_t i;
+               for (i = 0; i < SDB_STATIC_ARRAY_LEN(reserved_words); ++i)
+                       if (! strcasecmp(reserved_words[i].name, yytext))
+                               return reserved_words[i].id;
 
                yylval->str = strdup(yytext);
                return IDENTIFIER;