X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Ffrontend%2Fscanner.l;h=dd2a86cf5273b4e5e3c450c02306820b282a1a46;hb=22ab0383bb3117c4ebe6addb0cdb18929fed1c0f;hp=cd7ea8513109fd266437b10dfaf5a2428b55aec3;hpb=4215d1d8c69367c1d43bed9d39d428a92b329a92;p=sysdb.git diff --git a/src/frontend/scanner.l b/src/frontend/scanner.l index cd7ea85..dd2a86c 100644 --- a/src/frontend/scanner.l +++ b/src/frontend/scanner.l @@ -27,6 +27,11 @@ %{ +#if HAVE_CONFIG_H +# include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include "frontend/connection.h" #include "frontend/parser.h" #include "frontend/grammar.h" #include "utils/error.h" @@ -35,6 +40,8 @@ #include +#define YY_EXTRA_TYPE sdb_fe_yyextra_t * + void sdb_fe_yyerror(YYLTYPE *lval, sdb_fe_yyscan_t scanner, const char *msg); @@ -67,6 +74,8 @@ csc_inside ([^*/]+|[^*]\/|\*[^/]) csc_end \*\/ identifier ([A-Za-z_][A-Za-z_0-9$]*) +/* TODO: fully support SQL strings */ +string ('[^']*') %% @@ -77,27 +86,53 @@ identifier ([A-Za-z_][A-Za-z_0-9$]*) {csc_inside} { /* ignore */ } {csc_end} { BEGIN(INITIAL); } <> { - 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, "LIST")) return LIST; - + else if (! strcasecmp(yytext, "LOOKUP")) + return LOOKUP; + else if (! strcasecmp(yytext, "NOT")) + return NOT; + else if (! strcasecmp(yytext, "OR")) + return OR; + 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; + } + += { return CMP_EQUAL; } +!= { return CMP_NEQUAL; } +=~ { return CMP_REGEX; } +!~ { return CMP_NREGEX; } -. { /* do nothing for now */ } +. { /* 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", @@ -105,9 +140,14 @@ sdb_fe_scanner_init(const char *str) 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 */