X-Git-Url: https://git.tokkee.org/?p=sysdb.git;a=blobdiff_plain;f=src%2Ftools%2Fsysdb%2Fscanner.l;h=fb7b9d5fe92c3e7e9895a048b6ae2b229150faad;hp=4d9fea5bc6c1f501371739a40f09a4ebd017b40a;hb=032c425898676e71f2a928cbda48d35d1cdc2900;hpb=39a45905e0b237e458b1826ff9b4fad1c4a59550 diff --git a/src/tools/sysdb/scanner.l b/src/tools/sysdb/scanner.l index 4d9fea5..fb7b9d5 100644 --- a/src/tools/sysdb/scanner.l +++ b/src/tools/sysdb/scanner.l @@ -38,16 +38,19 @@ #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), &(result), (max_size)) + sdb_input_readline((buf), (size_t *)&(result), (max_size)) #define APPEND() \ do { \ + if (! isspace((int)yytext[0])) \ + sysdb_input->have_input = 1; \ sysdb_input->query_len += strlen(yytext); \ } while (0) @@ -58,12 +61,11 @@ %option yylineno %option nodefault %option noyywrap -%option verbose %option warn %x CSC -whitespace ([ \t\n\r\f]+) +newline (\n|\r\n) simple_comment ("--"[^\n\r]*) /* @@ -73,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); } @@ -85,15 +95,23 @@ 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_input_exec_query(); } +";\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(); } +. { APPEND(); } %%