diff --git a/src/frontend/scanner.l b/src/frontend/scanner.l
index 4dcd5e2a4f0cb196d986e769e77bb68cac7b97d7..f70f60f84dab33618a7ae84a67771ec33e0a022f 100644 (file)
--- a/src/frontend/scanner.l
+++ b/src/frontend/scanner.l
# include "config.h"
#endif /* HAVE_CONFIG_H */
# include "config.h"
#endif /* HAVE_CONFIG_H */
+#include "core/data.h"
#include "frontend/connection.h"
#include "frontend/parser.h"
#include "frontend/grammar.h"
#include "frontend/connection.h"
#include "frontend/parser.h"
#include "frontend/grammar.h"
#include <errno.h>
#include <string.h>
#include <errno.h>
#include <string.h>
+#include <stdlib.h>
#define YY_EXTRA_TYPE sdb_fe_yyextra_t *
#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);
void
sdb_fe_yyerror(YYLTYPE *lval, sdb_fe_yyscan_t scanner, const char *msg);
csc_inside ([^*/]+|[^*]\/|\*[^/])
csc_end \*\/
csc_inside ([^*/]+|[^*]\/|\*[^/])
csc_end \*\/
+/*
+ * Strings and identifiers.
+ */
identifier ([A-Za-z_][A-Za-z_0-9$]*)
/* TODO: fully support SQL strings */
string ('[^']*')
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})
+float1 ([\+\-]?[0-9]+\.[0-9]*([Ee][\+\-]?[0-9]+)?)
+float2 ([\+\-]?[0-9]*\.[0-9]+([Ee][\+\-]?[0-9]+)?)
+float3 ([\+\-]?[0-9]+[Ee]\-[0-9]+)
+float4 ([\+\-]?[Ii][Nn][Ff]([Ii][Nn][Ii][Tt][Yy])?)
+float5 ([Nn][Aa][Nn])
+float ({float1}|{float2}|{float3}|{float4}|{float5})
+
%%
{whitespace} |
%%
{whitespace} |
}
{identifier} {
}
{identifier} {
- /* XXX: simplify handling of reserved words */
- if (! strcasecmp(yytext, "FETCH"))
- return FETCH;
- else if (! strcasecmp(yytext, "LIST"))
- return LIST;
- else if (! strcasecmp(yytext, "LOOKUP"))
- return LOOKUP;
- 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;
yylval->str = strdup(yytext);
return IDENTIFIER;
yylval->str = strdup(yytext + 1);
return STRING;
}
yylval->str = strdup(yytext + 1);
return STRING;
}
+{integer} {
+ yylval->data.data.integer = (int64_t)strtoll(yytext, NULL, 10);
+ yylval->data.type = SDB_TYPE_INTEGER;
+ return INTEGER;
+ }
+{float} {
+ yylval->data.data.decimal = strtod(yytext, NULL);
+ yylval->data.type = SDB_TYPE_DECIMAL;
+ return FLOAT;
+ }
+
+= { return CMP_EQUAL; }
+!= { return CMP_NEQUAL; }
+=~ { return CMP_REGEX; }
+!~ { return CMP_NREGEX; }
+\< { return CMP_LT; }
+\<= { return CMP_LE; }
+\>= { return CMP_GE; }
+\> { return CMP_GT; }
+\|\| { return CONCAT; }
. { /* XXX: */ return yytext[0]; }
. { /* XXX: */ return yytext[0]; }