diff --git a/src/frontend/scanner.l b/src/frontend/scanner.l
index cd7ea8513109fd266437b10dfaf5a2428b55aec3..ef30682b45b837f8cb931f1e7257f7568ddd3f2b 100644 (file)
--- a/src/frontend/scanner.l
+++ b/src/frontend/scanner.l
%{
+#if 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 "utils/error.h"
#include <errno.h>
#include <string.h>
+#include <stdlib.h>
+
+#define YY_EXTRA_TYPE sdb_fe_yyextra_t *
void
sdb_fe_yyerror(YYLTYPE *lval, sdb_fe_yyscan_t scanner, const char *msg);
csc_end \*\/
identifier ([A-Za-z_][A-Za-z_0-9$]*)
+/* TODO: fully support SQL strings */
+string ('[^']*')
+
+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})
%%
<CSC>{csc_inside} { /* ignore */ }
<CSC>{csc_end} { BEGIN(INITIAL); }
<CSC><<EOF>> {
- sdb_fe_yyerror(yylval, yyscanner, "unterminated C-style comment");
+ sdb_fe_yyerror(yylloc, yyscanner, "unterminated C-style comment");
return SCANNER_ERROR;
}
{identifier} {
- /* XXX */
- if (! strcasecmp(yytext, "LIST"))
+ /* 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;
+
+ yylval->str = strdup(yytext);
return IDENTIFIER;
}
+{string} {
+ yytext[yyleng - 1] = '\0';
+ 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;
+ }
-. { /* do nothing for now */ }
+= { return CMP_EQUAL; }
+!= { return CMP_NEQUAL; }
+=~ { return CMP_REGEX; }
+!~ { return CMP_NREGEX; }
+\< { return CMP_LT; }
+\<= { return CMP_LE; }
+\>= { return CMP_GE; }
+\> { return CMP_GT; }
+
+. { /* XXX: */ return yytext[0]; }
%%
sdb_fe_yyscan_t
-sdb_fe_scanner_init(const char *str)
+sdb_fe_scanner_init(const char *str, int len, sdb_fe_yyextra_t *yyext)
{
yyscan_t scanner;
+ if (! str)
+ return NULL;
+
if (sdb_fe_yylex_init(&scanner)) {
char errbuf[1024];
sdb_log(SDB_LOG_ERR, "frontend: yylex_init failed: %s",
return NULL;
}
+ sdb_fe_yyset_extra(yyext, scanner);
+
+ if (len < 0)
+ len = strlen(str);
+
/* the newly allocated buffer state (YY_BUFFER_STATE) is stored inside the
* scanner and, thus, will be freed by yylex_destroy */
- yy_scan_string(str, scanner);
+ sdb_fe_yy_scan_bytes(str, len, scanner);
return scanner;
} /* sdb_fe_scanner_init */