diff --git a/src/frontend/scanner.l b/src/frontend/scanner.l
index f300e46d73160d906f841dd3c421f125d3a93fcc..61f1743fa60560c69f2cf5835f9c49827e760b17 100644 (file)
--- a/src/frontend/scanner.l
+++ b/src/frontend/scanner.l
%{
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif /* HAVE_CONFIG_H */
+
#include "frontend/connection.h"
#include "frontend/parser.h"
#include "frontend/grammar.h"
csc_end \*\/
identifier ([A-Za-z_][A-Za-z_0-9$]*)
+/* TODO: fully support SQL strings */
+string ('[^']*')
%%
<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, "FETCH"))
+ return FETCH;
+ else if (! strcasecmp(yytext, "LIST"))
return LIST;
+ else if (! strcasecmp(yytext, "LOOKUP"))
+ return LOOKUP;
+ else if (! strcasecmp(yytext, "WHERE"))
+ return WHERE;
+ yylval->str = strdup(yytext);
return IDENTIFIER;
}
+{string} {
+ yytext[yyleng - 1] = '\0';
+ yylval->str = strdup(yytext + 1);
+ return STRING;
+ }
. { /* do nothing for now */ }
%%
sdb_fe_yyscan_t
-sdb_fe_scanner_init(const char *str, sdb_fe_yyextra_t *yyext)
+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",
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 */