X-Git-Url: https://git.tokkee.org/?p=sysdb.git;a=blobdiff_plain;f=src%2Ftools%2Fsysdb%2Fscanner.l;h=16defa61859085dc20dad932c8f812986af494e3;hp=c9b527e7d9cdb74785f891b6ea99553ff478a9b3;hb=b6c730c2d0cf400127da5ca96b51abd4ad335c0c;hpb=a006a526f16e790dbeae6ef96ed61f506310b66f diff --git a/src/tools/sysdb/scanner.l b/src/tools/sysdb/scanner.l index c9b527e..16defa6 100644 --- a/src/tools/sysdb/scanner.l +++ b/src/tools/sysdb/scanner.l @@ -32,8 +32,11 @@ * find queries (terminated by semicolon). */ +#if HAVE_CONFIG_H +# include "config.h" +#endif /* HAVE_CONFIG_H */ + #include "tools/sysdb/input.h" -#include "tools/sysdb/command.h" #include @@ -41,15 +44,15 @@ # undef YY_INPUT #endif #define YY_INPUT(buf, result, max_size) \ - sdb_input_readline(sdb_input, (buf), &(result), (max_size)) + sdb_input_readline((buf), (size_t *)&(result), (max_size)) #define APPEND() \ do { \ - sdb_input->query_len += strlen(yytext); \ + 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 @@ -62,7 +65,7 @@ static sdb_input_t *sdb_input; %x CSC -whitespace ([ \t\n\r\f]+) +newline (\n|\r\n) simple_comment ("--"[^\n\r]*) /* @@ -72,11 +75,19 @@ csc_start \/\* csc_inside ([^*/]+|[^*]\/|\*[^/]) csc_end \*\/ -identifier ([A-Za-z_][A-Za-z_0-9$]*) +/* + * Strings. + */ +/* TODO: fully support SQL strings */ +string ('([^']|'')*') %% -{whitespace} { APPEND(); } + /* + * 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); } @@ -84,23 +95,25 @@ identifier ([A-Za-z_][A-Za-z_0-9$]*) {csc_end} { APPEND(); BEGIN(INITIAL); } <> { return -1; } -{identifier} { APPEND(); } +{string} { APPEND(); } /* * The following rules are specific to the command line tool. */ -";" { APPEND(); sdb_command_exec(sdb_input); } +";\n" { APPEND(); sdb_input_exec_query(); } +";" { APPEND(); sdb_input_exec_query(); } -. { APPEND(); } +{newline} { + APPEND(); + if (! sysdb_input->have_input) + /* give the input module a chance to do stuff on empty lines */ + sdb_input_exec_query(); + } -%% +. { APPEND(); } -void -sdb_input_set(sdb_input_t *new_input) -{ - sdb_input = new_input; -} /* sdb_input_set */ +%% /* vim: set tw=78 sw=4 ts=4 noexpandtab : */