diff --git a/src/frontend/scanner.l b/src/frontend/scanner.l
index a7b72b43794541985e722ca2f2c6ea3a61848e12..4bd5655e04bd9d870ccadcafa5da15d9c7c3ba74 100644 (file)
--- a/src/frontend/scanner.l
+++ b/src/frontend/scanner.l
#define YY_EXTRA_TYPE sdb_fe_yyextra_t *
+static struct {
+ const char *name;
+ int id;
+} reserved_words[] = {
+ { "AND", AND },
+ { "FETCH", FETCH },
+ { "FILTER", FILTER },
+ { "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);
csc_inside ([^*/]+|[^*]\/|\*[^/])
csc_end \*\/
+/*
+ * Strings and identifiers.
+ */
identifier ([A-Za-z_][A-Za-z_0-9$]*)
/* TODO: fully support SQL strings */
string ('[^']*')
+/*
+ * Numeric constants.
+ */
dec ([\+\-]?[0-9]+)
exp ([\+\-]?[0-9]+[Ee]\+?[0-9]+)
integer ({dec}|{exp})
}
{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, "NOT"))
- return NOT;
- else if (! strcasecmp(yytext, "NULL"))
- return NULL_T;
- else if (! strcasecmp(yytext, "OR"))
- return OR;
- else if (! strcasecmp(yytext, "WHERE"))
- return WHERE;
+ 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;
\<= { return CMP_LE; }
\>= { return CMP_GE; }
\> { return CMP_GT; }
+\|\| { return CONCAT; }
. { /* XXX: */ return yytext[0]; }