X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Ftools%2Fsysdb%2Fscanner.l;h=fb7b9d5fe92c3e7e9895a048b6ae2b229150faad;hb=0a3dd5b9b97e25156412a95bcecf25f8d75c72fc;hp=07a941370d9eb5f419674806544d9337f3f21f36;hpb=4215d1d8c69367c1d43bed9d39d428a92b329a92;p=sysdb.git diff --git a/src/tools/sysdb/scanner.l b/src/tools/sysdb/scanner.l index 07a9413..fb7b9d5 100644 --- a/src/tools/sysdb/scanner.l +++ b/src/tools/sysdb/scanner.l @@ -32,18 +32,28 @@ * find queries (terminated by semicolon). */ +#if HAVE_CONFIG_H +# include "config.h" +#endif /* HAVE_CONFIG_H */ + #include "tools/sysdb/input.h" +#include +#include + #ifdef YY_INPUT # undef YY_INPUT #endif #define YY_INPUT(buf, result, max_size) \ + sdb_input_readline((buf), (size_t *)&(result), (max_size)) + +#define APPEND() \ do { \ - sdb_input_readline(sdb_input, (buf), &(result), (max_size)); \ + if (! isspace((int)yytext[0])) \ + sysdb_input->have_input = 1; \ + sysdb_input->query_len += strlen(yytext); \ } while (0) -static sdb_input_t *sdb_input; - %} %option interactive @@ -51,20 +61,59 @@ static sdb_input_t *sdb_input; %option yylineno %option nodefault %option noyywrap -%option verbose %option warn -%% +%x CSC -. { /* do nothing */ } +newline (\n|\r\n) +simple_comment ("--"[^\n\r]*) + +/* + * C style comments + */ +csc_start \/\* +csc_inside ([^*/]+|[^*]\/|\*[^/]) +csc_end \*\/ + +/* + * Strings. + */ +/* TODO: fully support SQL strings */ +string ('([^']|'')*') %% -void -sdb_input_set(sdb_input_t *new_input) -{ - sdb_input = new_input; -} /* sdb_input_set */ + /* + * Here, we only care about syntax elements that may include semicolons + * and escape their meaning as a query terminator. + */ + +{simple_comment} { APPEND(); } + +{csc_start} { APPEND(); BEGIN(CSC); } +{csc_inside} { APPEND(); } +{csc_end} { APPEND(); BEGIN(INITIAL); } +<> { return -1; } + +{string} { APPEND(); } + + /* + * The following rules are specific to the command line tool. + */ + +";\n" { APPEND(); sdb_input_exec_query(); } +";" { APPEND(); sdb_input_exec_query(); } + +{newline} { + APPEND(); + if (! sysdb_input->have_input) + /* give the input module a chance to do stuff on empty lines */ + sdb_input_exec_query(); + } + +. { APPEND(); } + +%% /* vim: set tw=78 sw=4 ts=4 noexpandtab : */